Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 新表单字段中的“无法识别的表达式”_Javascript_Jquery_Forms - Fatal编程技术网

Javascript 新表单字段中的“无法识别的表达式”

Javascript 新表单字段中的“无法识别的表达式”,javascript,jquery,forms,Javascript,Jquery,Forms,我遇到了这样一种情况:我有一个用javascript编写的表单,该表单为详细说明ir名称的人创建个人资料。无论如何,我尝试向该表单添加一些新字段,但当我尝试编辑个人资料信息时,添加的每个新字段都会抛出一个无法识别的表达式错误 从fname到owner的所有字段都很好,但是下面的任何字段都会抛出错误。与上面的解释一致,owner下面的所有字段都是我最近添加的新字段 createForm: function(n) { item = $("<table> \

我遇到了这样一种情况:我有一个用javascript编写的表单,该表单为详细说明ir名称的人创建个人资料。无论如何,我尝试向该表单添加一些新字段,但当我尝试编辑个人资料信息时,添加的每个新字段都会抛出一个无法识别的表达式错误

从fname到owner的所有字段都很好,但是下面的任何字段都会抛出错误。与上面的解释一致,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;
    },
错误消息的确切措辞示例如下:

错误:语法错误,无法识别的表达式:input[name=pedu

所有相关的javascript函数都可以

提前谢谢


注意:这是文章中描述的问题的演变:

您缺少几个右括号

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

item.find("input[name=pedu]").attr("value",p.edu);
最后,您在jQuery选择器中忘记了几个]选项


编辑:从“pedu”和下面,只需添加最后的大括号,应该就是全部大括号。

注意,要设置表单字段值,可以说.valp.fname,而不是.attrvalue,p.fname.::下巴下垂,脸变红,头撞到桌子::效果很好!我已经做了大概8个小时了。在这一切之后,我希望找到一些我对javascript一无所知的东西;我已经知道我的语法很糟糕了非常感谢你!