Javascript jquery中的选择选项动态字段不工作

Javascript jquery中的选择选项动态字段不工作,javascript,jquery,select,Javascript,Jquery,Select,jQueryfunction{ var currentCount=0; jQuery'addMoreEmail'。单击函数{ currentCount=克隆'MoreEmailDetails','MoreEmails',currentCount; 返回false; }; 函数cloningfrom,to,counter{ var clone=$from.clone; //console.logclone; 计数器++; //替换输入属性: clone.find':input'.eachfunct

jQueryfunction{ var currentCount=0; jQuery'addMoreEmail'。单击函数{ currentCount=克隆'MoreEmailDetails','MoreEmails',currentCount; 返回false; }; 函数cloningfrom,to,counter{ var clone=$from.clone; //console.logclone; 计数器++; //替换输入属性: clone.find':input'.eachfunction{
var name=jQuerythis.attr'name'.replace0,计数器; var id=jQuerythis.attr'id'.replace0,计数器; jQuerythis.attr{ “名称”:名称, “id”:id }瓦尔先生; }; //替换属性的标签: 克隆。查找“标签”。每个函数{ var newFor=jQuerythis.attr'for'.replace0,计数器; jQuerythis.attr'for',newFor; }; //替换html标记之间的文本: clone=clone.html.replace1,计数器; jQueryto.beforeclone; 返回计数器; } }; 名字 名字 选择一个国家 东南欧 国 主要电子邮件
您需要为jQuerythis.attr'name'添加空检查

下面是修改后的JS代码块

clone.find(':input').each(function() {
    if(jQuery(this).attr('name')) {
  var name = jQuery(this).attr('name').replace(0, counter);
  var id = jQuery(this).attr('id').replace(0, counter);
  jQuery(this).attr({
    'name': name,
    'id': id
  }).val(); }
});

哪一行抛出错误?var name=jQuerythis.attr'name'.replace0,counter;var id=jQuerythis.attr'id'.replace0,计数器;jQuerythis.attr{'name':name'id':id}.val'1';在上一个注释中获取代码上方的错误,该代码应该做什么?它没有做什么,它应该做什么?它做了什么不应该做的事情?如果使用.prop而不是.attr呢?