我遇到了一种情况,我有一个用 javascript 编写的表单,该表单为详细说明他们的姓名 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;
},
错误消息的准确措辞示例如下:
错误:语法错误,无法识别的表达式:input[name=pedu
所有相关的javascript函数都可以在这里查看。
提前致谢。
注意:这是帖子中描述的问题的演变:Problems Saving data in added fields to a javascript form