【问题标题】:how to make my click reach the inner (contentEditable) div?如何让我的点击到达内部(contentEditable)div?
【发布时间】:2013-10-02 12:39:00
【问题描述】:

我有一个无法将光标放入的可编辑文本框,可能是因为当我单击以移动光标或选择文本块时,框架 DIV 正在捕获单击。我认为可拖动与它有关,虽然不确定。

非常感谢任何意见。

这是我的代码(“curObj”是框架,“inner”是我设置为可编辑的 div)。

function textbox_editable() {
    var curObj = window.curObj;
    var inner = '#' + $(curObj).attr("id") + ' .object_inner';

    //unless the doubleclick was in a textbox that is already activated for editability...
    if ( $(inner).attr('contentEditable') != 'true' ) {
        $(inner).attr('contentEditable',true); //set attribute editable
        $(curobj).draggable( "destroy" );//remove draggable (it blocks the click-to-move-cursor functionality
        $(curobj).resizable( "destroy" );//remove resizable (it blocks the click-to-move-cursor functionality
        //make cursor text
        $(inner).css( "cursor", 'text' );
        setEndOfContenteditable(inner)
    }
}

//called when we are done editing the contents of a textbox
function textbox_uneditable() {

    $( ".object_textbox .object_inner" ).removeAttr('contentEditable'); //remove editable attribute if it was present
    $( ".object_textbox" ).draggable(); //reinstate draggable
    $( ".object_textbox" ).resizable(); //reinstate draggable
    //restore cursor
    $( ".object_textbox" ).css( "cursor", 'move' );
}

【问题讨论】:

  • 如果你设置 true/false,你应该使用 prop() 而不是 attr

标签: jquery draggable contenteditable resizable


【解决方案1】:

哦.. 错字,我在销毁方法上使用了 curobj 而不是 curObj... 现在可以使用了。除了 setEndOfContenteditable 不起作用,但这是一个不同的问题。

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多