[英]function doesn't work as another function parameter
Can anyone tell me how to pass the draggable
function as a parameter for clickit
, which is an AJAX function? 谁能告诉我如何将
draggable
函数作为clickit
的参数clickit
, clickit
是AJAX函数? I want to pass draggable
as a parameter to attach it to a dynamically added element. 我想将
draggable
作为参数传递,以将其附加到动态添加的元素上。 I can't get it to work defining the draggable function and pass it to clickit
. 我无法定义可拖动函数并将其传递给
clickit
。
function clickit(fun){
$.ajax({
'url' : "url",
'dataType' : 'json',
'success' : function(data){
var item_html ="";
$.each(data.query.results.json,function(i,k){
item_html += '<div class="dialog"><h3>'+k+'</h3></div>'
});
$('.area').html(item_html);
fun;
}
});
}
$('button').click(function(){
var funpara = $('.dialog').draggable();
clickit(funpara)
});
Here's the one that works: 这是可行的一种:
function clickit(){
$.ajax({
'url' : "url",
'dataType' : 'json',
'success' : function(data){
var item_html ="";
$.each(data.query.results.json,function(i,k){
item_html += '<div class="dialog"><h3>'+k+'</h3></div>'
});
$('.area').html(item_html);
$('.dialog').draggable();
}
});
}
$('button').click(function(){
clickit()
});
It looks like the parameter fun
cannot be passed to the success function. 看来参数
fun
无法传递给成功函数。
It looks like you want to invoke fun
, but currently you're just referencing to it without the invocation ()
看起来您想调用
fun
,但是当前您只是在没有调用()
情况下引用它
function (data) {
var item_html = "";
$.each(data.query.results.json, function (i, k) {
item_html += '<div class="dialog"><h3>' + k + '</h3></div>';
});
$('.area').html(item_html);
fun();
}
In your context, it looks like you want to invoke $('.dialog').draggable()
, so fun
should look more like this 在您的上下文中,您似乎想调用
$('.dialog').draggable()
,所以fun
应该更像这样
function fun(o) {
return $('.dialog').draggable(o);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.