2013-08-30 32 views
0

我遇到了一种情况,我使用javascript编写了一个表单,为人们详细描述了ir名称生物等创建配置文件等等。无论如何,我尝试在此表单中添加一些新字段但是当我尝试编辑配置文件信息时,我添加的每个新字段都会抛出“无法识别的表达式”错误。“无法识别的表达式”在新的表单域中

从“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&mdash;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; 
    }, 

一个错误消息的确切的措辞的一个例子是:

Error: Syntax error, unrecognized expression: input[name=pedu

所有相关JavaScript函数可以是预先viewed here.

感谢。

注:这是在后描述的问题的演变:Problems saving data in added fields to a javascript form

+1

请注意,要设置表单字段值,您可以使用'.val(p.fname)'而不是'.attr(“value”,p.fname)'。 – nnnnnn

回答

3

你在最后

编辑忘了在你的jQuery选择几个]:从“柏都”上下,只是添加的最后括号这应该是所有其中。

+0

::下降,脸变成红色,头撞表:: ::完美的作品!我大概已经8个小时了。毕竟,我希望找出一些我不了解javascript的东西;我已经知道我在语法上很糟糕! :-) 非常感谢! – neanderslob

+0

老板没问题,我一直在那里相信我。很高兴它的作品。 –

6

你缺少一些右括号。

item.find("input[name=pedu").attr("value",p.edu); 

应该

item.find("input[name=pedu]").attr("value",p.edu); 
相关问题