摘要:我正在尝试将字段添加到组织中的成员的某种在线个人资料中,用javascript编写。我真的很喜欢这种语言,所以我发现自己需要一些帮助。
背景(工作原理):该脚本允许用户点击“添加”按钮,填写一个包含基本字段的表单(名字,姓氏,位置,照片,等等等等等等等等) )然后通过php脚本将数据存储在mysql数据库中。添加此人后,他们会进入显示照片和姓名的列表;可以通过单击每张照片来编辑配置文件。用户可以根据需要添加人员。请参阅下面的图片,了解界面(真实人物的图像/名称已经过像素化,以保护无辜......来自某事物):
我正在尝试做什么(什么不起作用):所以这一切都很有效......可能是因为我没有写那部分。当我尝试将一组字段(ownership_percentage,edu,技能,教授,奖励,社区,年份和补偿)添加到原始字段正下方的弹出窗体时,就会出现问题:
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;
},
和
var person = {
id: $("#dialog").data("person"),
fname: $("#dialog input[name=pfname]").attr("value"),
lname: $("#dialog input[name=plname]").attr("value"),
title: $("#dialog input[name=ptitle]").attr("value"),
bio: $("#dialog textarea[name=pbio]").attr("value"),
photo: $("#dialog input[name=photo]").attr("value"),
owner: $("#dialog input[name=owner]").attr("value"),
ownership_percentage: $("#dialog input[name=ownership_percentage]").attr("value"),
edu: $("#dialog input[name=pedu]").attr("value"),
skills: $("#dialog input[name=pskills]").attr("value"),
prof: $("#dialog input[name=pprof]").attr("value"),
awards: $("#dialog input[name=pawards]").attr("value"),
community: $("#dialog input[name=pcommunity]").attr("value"),
years: $("#dialog input[name=pyears]").attr("value"),
compensation: $("#dialog input[name=pcompensation]").attr("value"),
}
问题(它是如何工作的):
我已经检查了php保存脚本,一切都井然有序;似乎我在我的javascript中遗漏了一些内容,将这些新值传递给数组以供php处理..我无法想到可能导致这种差异的原因并且正在寻找想法。
非常感谢任何帮助,非常感谢!
的txt文件答案 0 :(得分:0)
Anticlimactic解决方案由RUJordan提供一个单独的问题,我发布了关于&#34;无法识别的表达错误&#34;
来源:https://stackoverflow.com/a/18541225/2540204
问题是我错过了所有新表单字段的右括号,所以
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);
}
<强>成了强>
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);
}