twitter-bootstrap 单击时 X 可编辑切换。如何禁用原生元素点击?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21308580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:49:18  来源:igfitidea点击:

X-editable toggle on click. How to disable native element click?

javascriptjquerytwitter-bootstrapx-editable

提问by user991

Problem is that cant disable native "on click" event that triggers x-editable to transform into textarea. I want that only Button could tranfsorm text to textarea, So that on text is non-clickable.

问题是无法禁用触发 x-editable 转换为 textarea 的原生“点击”事件。我希望只有 Button 可以将文本转换为 textarea,这样文本是不可点击的。

I found questions how to trigger x-editable on other element click. But how to disable native text click and leave only other element's event ?

我发现了如何在其他元素点击时触发 x-editable 的问题。但是如何禁用原生文本单击并仅保留其他元素的事件?

Fiddle with problem is here:

摆弄问题在这里:

This part works great:

这部分效果很好:

$('.edit-post-button').on('click', function(e) {
    e.preventDefault();
    e.stopPropagation();
    $textarea = $(this).closest('.media-body').find('.editable');
    $textarea.editable('toggle');        
});

But when trying to disable native text click, it wont work, or I'm doing something wrong here ?

但是当试图禁用原生文本点击时,它不起作用,或者我在这里做错了什么?

$('.editable-post-textarea').on('click', function(e) {
    console.log('native-click-triggered!');
    e.stopPropagation();
});

Here is sample with my problem: http://jsfiddle.net/jjdJX/64/

这是我的问题示例:http: //jsfiddle.net/jjdJX/64/

So how to disable native "click" event on textarea, and leave trigger only on "EDIT TEXT" button?

那么如何禁用 textarea 上的原生“click”事件,而只在“EDIT TEXT”按钮上触发?

回答by rgtk

Disable elements' click event using:

使用以下方法禁用元素的点击事件:

$('.editable-post-textarea').off('click');

Fiddle: http://jsfiddle.net/jjdJX/65/

小提琴:http: //jsfiddle.net/jjdJX/65/

回答by Andrea D'Amico

In version 1.5.1 you can set a 'toggle' option with a 'manual' value

在 1.5.1 版中,您可以使用“手动”值设置“切换”选项

$('.editable').editable({
  toggle: 'manual'
});

Doing this has the nice side effect of removing the dashed-underline decoration in the editable field.

这样做有一个很好的副作用,即删除可编辑字段中的虚线下划线装饰。

source official x-editable docs

官方 x 可编辑文档