Jquery Sortable - Disable onclick=“” while sorting

2019-06-27 21:49发布

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

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

Peter

2条回答
Animai°情兽
2楼-- · 2019-06-27 22:36

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

查看更多
对你真心纯属浪费
3楼-- · 2019-06-27 22:37

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;
    }
});
查看更多
登录 后发表回答