我遇到了jQuery中clone()函数的问题。我有一个事件监听器,当它失去焦点时,它会简单地消隐。在克隆页面上的任何内容之前,该功能正在按预期工作。但是,当我调用clone函数时,不仅侦听器不在克隆块上工作,而且它显然也完全取消绑定侦听器和我可以删除的前一个字段不再起作用。
//Blanks out prsy field when the user leaves the field
$(document.body).on('blur','.prsy-field', function () {
$(this).val("");
});
这是克隆功能:
$('#clonedInput1').clone(true, true)
.insertAfter($(this).prev().prev())
.attr("id", "clonedInput" + cloneIndex)
.find("*")
.each(function () {
var id = this.id || "";
var name = $(this).attr("name") || "";
if (id != "") {
this.id += "-" + cloneIndex;
}
if (name != "") {
$(this).attr("name", $(this).attr("name") + "-" + cloneIndex);
}
}).find('input').val('') //clear out the inputs
.on('click', 'a.add-project', clone);
我尝试使用on,live,document或尝试直接定位prsy-field输入的几个变体,但到目前为止还没有工作。任何人都知道为什么克隆函数解绑事件监听器?
最佳