【问题标题】:jQuery UI sortable & contenteditable=truejQuery UI 可排序 & contenteditable=true
【发布时间】:2017-05-13 09:24:18
【问题描述】:

我正在使用 jquery sortable 和 contenteditable 问题是当我使用 jquery sortable 时 contenteditable 不起作用所以我已经在 stackoverflow 上搜索了我得到了解决方案但是当我现在实现它时,问题出在 mousedown 事件上,可排序是不工作。

我在做什么。

Here is the stackoverflow link

<div class="sortable">
  <div id="" style="background: #eee; width: 80%; margin: 10px auto; padding: 10px;">
    <p contenteditable="true" style="padding: 5px;">Add your text here.</p>  </div>
    <div id="" style="background: #eee; width: 80%; margin: 10px auto; padding: 10px;">
    <p contenteditable="true" style="padding: 5px;">Add your text here.</p>  </div>
    <div id="" style="background: #eee; width: 80%; margin: 10px auto; padding: 10px;">
    <p contenteditable="true" style="padding: 5px;">Add your text here.</p>  </div>
</div>

首先我使用这个代码

$('.sortable').sortable();

我第二次使用这段代码

$('.sortable').on('onmousedown', function() {
        $(".sortable").sortable({
            cursor: 'move'
        });
    })

【问题讨论】:

  • 将 onmousedown 更改为 mousedown。$('.sortable').on('mousedown', function() { $(".sortable").sortable({ cursor: 'move' }); })

标签: javascript jquery html jquery-ui contenteditable


【解决方案1】:

onmousedown 更改为mousedown

$('.sortable').on('mousedown', function() {
    $(".sortable").sortable({
        cursor: 'move'
    });
})

同样在 p 的点击事件上销毁 sortable

 $('p').on('click', function() {
    $( ".sortable" ).sortable( "destroy" );
});

http://jsfiddle.net/fum9sf2m/

【讨论】:

  • 很难摧毁它。我的意思是我必须单击两次才能销毁可排序,然后单击两次才能重新获得可排序,这会不会有点顺利
【解决方案2】:
$(window).on('mouseup','.sortable',function(){
     $( ".sortable" ).sortable( "destroy" );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    • 2018-06-26
    • 2011-02-18
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    相关资源
    最近更新 更多