nea*_*lob 0 javascript forms jquery
我遇到了一个情况,我有一个用javascript编写的表单,为详细说明ir name bio等的人创建配置文件.无论如何,我试图在这个表单中添加一些新字段,但我添加的每个新字段都是"我尝试编辑配置文件信息时出现"无法识别的表达式"错误.
从"fname"到"owner"的所有字段都很好,但是低于该值的任何字段都会引发错误.与上面的解释一致,"所有者"下面的所有字段都是我最近添加的新字段.
createForm: function(n) {
item = $("<table> \
<tr><th>Name</th><td class='twoinput'><input name='pfname' placeholder='Jane'/><input name='plname' placeholder='Smith'/></tr> \
<tr><th>Title</th><td><input name='ptitle' placeholder='Chief Executive Officer'/></tr> \
<tr><th>Short Bio</th><td><textarea name='pbio'/></textarea></td></tr> \
<tr><th>Photo</th><td><input id='photo_upload' name='photo'/> <input type='button' id='photo_button' value='Open Media Library'/></tr> \
<tr><td colspan='2'>(Optional) Upload a photo of <acronym title='Replace this with their first name?'>this person</acronym>. The bigger the better—don't worry, we'll scale this down for you.</td></tr> \
</table>\
<br/>\
<table>\
<tr><th>Education</th><td><textarea name='pedu'/></textarea></td></tr> \
<tr><th>Relevant Skills</th><td><textarea name='pskills'/></textarea></td></tr> \
<tr><th>Professional Experience</th><td><textarea name='pprof'/></textarea></td></tr> \
<tr><th>Awards & Recognition</th><td><textarea name='pawards'/></textarea></td></tr> \
<tr><th>Community Involvement</th><td><textarea name='pcommunity'/></textarea></td></tr> \
<tr><th>Years with the Company</th><td><input type='text' size='2' maxlength='2' name='pyears'/>years</td></tr>\
<tr><th>Compensation Details</th><td><textarea name='pcompensation'/></textarea></td></tr> \
</table>\
<br/>\
<table>\
<tr><td id='ownershipquestion' colspan='2'>Does this person have an ownership stake?</td><td id='ownershipbox'><input type='checkbox' id='part_owner' name='owner' value='1'/>Yes</td></tr>\
<tr><td id='ownershipperquestion' colspan='2'>What percentage does this person hold?</td><td id='ownershipperanswer'><input type='text' size='3' maxlength='3' id='ownership_percentage' name='ownership_percentage'/>%</td></tr>\
</table>");
if(n < upsmart.people.people.length) {
p = upsmart.people.people[n];
item.find("input[name=pfname]").attr("value",p.fname);
item.find("input[name=plname]").attr("value",p.lname);
item.find("input[name=ptitle]").attr("value",p.title);
item.find("textarea[name=pbio]").attr("value",p.bio);
item.find("input[name=photo]").attr("value",p.photo);
item.find("input[name=owner]").attr("value",p.owner);
item.find("input[name=ownership_percentage]").attr("value",p.ownership_percentage);
item.find("input[name=pedu").attr("value",p.edu);
item.find("input[name=pskills").attr("value",p.skills);
item.find("input[name=pprof").attr("value",p.prof);
item.find("input[name=pawards").attr("value",p.awards);
item.find("input[name=pcommunity").attr("value",p.community);
item.find("input[name=pyears").attr("value",p.years);
item.find("input[name=pcompensation").attr("value",p.compensation);
}
return item;
},
Run Code Online (Sandbox Code Playgroud)
错误消息的确切措辞的一个示例是:
错误:语法错误,无法识别的表达式:input [name = pedu
所有相关的javascript函数都可以在这里查看.
提前致谢.
注意:这是帖子中描述的问题的演变:将添加字段中的数据保存到javascript表单的问题
你缺少几个结束括号.
item.find("input[name=pedu").attr("value",p.edu);
Run Code Online (Sandbox Code Playgroud)
应该
item.find("input[name=pedu]").attr("value",p.edu);
Run Code Online (Sandbox Code Playgroud)