Jquery Sortable - Disable onclick=“” while sorting

久未见 提交于 2019-12-10 15:54:37

问题


is it possible to disable onclick="" while sorting?

I Have a working example here http://www.jsfiddle.net/V9Euk/59/

Peter


回答1:


If you don't want to do it with a flag variable as per @nigative , you can do the following with the start and stop methods:

$("#lop").sortable({
  revert: '100',
    placeholder: 'auo',
    start: function(event, ui) {
       ui.item[0].oldclick = ui.item[0].onclick;
       ui.item[0].onclick = null;     
    },
    stop: function(event, ui) {
       ui.item[0].onclick = ui.item[0].oldclick;
    }
});



回答2:


you can use start and stop options:

$( ".selector" ).sortable({
   start: function(event, ui) { ... },
   stop: function(event, ui) { ... }
});

Just create a flag and set to true when sorting started and to false when the sorting is over and in your onclick function check the flag first:

var isBeingSorted = false

$( ".selector" ).sortable({
   start: function(event, ui) { isBeingSorted = true; },
   stop: function(event, ui) { isBeingSorted = false; }
});

function printAlert(message){
   if(!isBeingSorted)
       alert(message);
}

And of course your onclicks should look like onclick="printAlert('sdfsdf')"

For more options look here



来源:https://stackoverflow.com/questions/3433366/jquery-sortable-disable-onclick-while-sorting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!