我有我的JQuery的一个问题。绑定当前正在运行的功能元素
我的代码是这样工作的,
有一个与输入框的名字在桌子底部的表中添加一个新的名称和作用,当两个输入框填写,代码增加输入框的值添加到新的表格行中。
我的问题是,添加的内容时,我想补充的输入框让更多的人可以加入另一行,但是......模糊运行时输入框失去焦点的功能/势必我原来的输入元素,并添加投入的下一行的时候,我基本上是试图绑定我目前正在运行的元素的功能...这是可能的,或者我应该怎么回事解决这个..
代码:
$('.add_new_castcrew').bind("blur",function(){
castCrewBlur(this);
});
function castCrewBlur(element){
if(castChangeLength == 2){
$('#newCast').removeAttr('id');
console.log("HAHAHAHA");
$('#cast_table').append("<tr id=\"newCast\"><td><input type=\"text\" value=\"Cast Member Name\" class=\"add_new_castcrew\" id=\"new_cast_name\"></td><td><input type=\"text\" value=\"Cast Member Role\" class=\"add_new_castcrew\" id=\"new_cast_role\"></td></tr>");
castChangeLength = 0;
$('#newCast.contentAdded ').each(function(){$(element).removeClass("contentAdded"); console.log("Removed"); });
$('.add_new_castcrew').bind("click",function(){
newCastCrewClick(this);
});
$('.add_new_castcrew').bind("click",function(){
castCrewBlur(this);
});
请格式化你的代码正确下一次。其中一部分似乎缺失。 – bfavaretto 2013-02-18 18:10:28
重要的代码就在那里。其余工作正常,这简直就是在那里,我结合模糊到新追加的输入框 – nmyster 2013-02-18 18:12:14
在你的问题中的代码部分结合'click'取代'两次click'然后'blur'。这会成为问题吗? – 2013-02-18 18:18:19