我的 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);
});