$(".foo").editable("script.php")
如何传递.foo
的母公司的ID作为参数?我试过
$(".foo").editable("script.php", {
submitdata: {
parent_id: $(this).parent().attr('id')
}
});
和我能想到的每一个变体,但它看起来像$(this)对象不在这个上下文中工作。
$(".foo").editable("script.php")
如何传递.foo
的母公司的ID作为参数?我试过
$(".foo").editable("script.php", {
submitdata: {
parent_id: $(this).parent().attr('id')
}
});
和我能想到的每一个变体,但它看起来像$(this)对象不在这个上下文中工作。
我只是这样做:(富)。
$(".foo").editable("script.php", { submitdata: { parent_id: $(".foo").parent().attr('id') } });
你也有一个错字在你的问题,你有$ .editable()而不是$( “富”)编辑()。如果这也是你的实际代码,那可能是问题的根源。
我这里有同样的问题,找到了以下解决方案:
$('.jeditable').each(function() {
var $this = $(this);
$this.editable('submit.jsp', {
submitdata : { parent_id : $this.parent().attr('id') }
});
});
这可行,但它可能值得解释发生了什么......引用`。(this)`.editable()`内部``不会工作,而是我们通过使用jQuery的`.each ()`。里面是对`.editable`的正常调用,但将jQuery对象复制到jEditable *可以读取的变量中 - 然后可以运行所有常用的jQuery命令。使用'$'而不是'var this'是区分正常变量和jQuery对象的备忘录 - http://stackoverflow.com/questions/205853/why-would-a-javascript-variable-start-with -a-美元符号 – 2012-11-22 16:54:54
你可以做一个Ajax调用,这样就可以通过一切(如果你正在寻找的未来,也许你要添加一些特征..)。
例子:
$('.edit').editable(
function(value, settings) {
// prepare the data, add all parameters you want
var data = "param1=value1" +
"¶m2=value2";
var ret = "";
// make the ajax call to do the work (not async)
$.ajax({
type: "POST",
url: "page.php",
data: data,
async: false,
success: function(msg) {
if (msg.length != 0) {
// set the value to write in the element
ret = msg;
}
}
});
// return the element to save into the element
return ret;
}, {
// set the jeditable setting
cssclass: 'classname'
}
);
我认为这个方法是每一个案件的更加灵活的手柄。
这只是一个错误的问题。 感谢您的答复,它确实得到了父母的ID,如果它是$(“#foo”)而不是$(“。foo”),那就没事了。但在这种情况下,它是一个类,还有多个$(“.foo”)......所以我需要它来引用它自己,而不是全班。 – Matthew 2009-04-09 15:12:41