为什么我无法做到这样的事情:
var $el = $(".sortable").sortable({
placeholder: "placeholder",
tolerance: "pointer",
handle: ".handle",
});
比称之为:
$(document).on('click', '.action', function() {
$.post("index.php", function(data) {
$el
});
});
而不是:
$(document).on('click', '.action', function() {
$.post("index.php", function(data) {
$(".sortable").sortable({
placeholder: "placeholder",
tolerance: "pointer",
handle: ".handle"
});
});
});
是否有其他方法只使用一行代码调用sortable,或者是否所有内容都需要包含在函数中?
答案 0 :(得分:0)
var foo = function(){
$(".sortable").sortable({
placeholder: "placeholder",
tolerance: "pointer",
handle: ".handle",
});
}
然后就这样做
$(document).on('click', '.action', function() {
$.post("index.php", function(data) {
foo();
});
});