Javascript 文本字段和 PHP 变量声明
$(document).ready(function(){
var skillctr = 1;
var experiencectr = 1;
var educationctr = 1;
var achievementctr = 1;
var historyctr = 1;
/*
Add Skills
*/
$("#addSkill").click(function () {
if(skillctr>10){
alert("WOW! But 10 skills are enough.");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'SkillDiv' + skillctr);
newTextBoxDiv.html('<label>Skill No. '+ skillctr + ' : </label>' +
'<input type="text" name="skill' + skillctr +
'" id="skill' + skillctr + '" value="" >');
newTextBoxDiv.appendTo("#SkillsBoxesGroup");
skillctr++;
});
那么我现在如何将生成的字段保存在数据库中的表中? 我该如何在 php 中声明该字段,例如 $_POST['skill']. 我需要帮助。请
$(document).ready(function(){
var skillctr = 1;
var experiencectr = 1;
var educationctr = 1;
var achievementctr = 1;
var historyctr = 1;
/*
Add Skills
*/
$("#addSkill").click(function () {
if(skillctr>10){
alert("WOW! But 10 skills are enough.");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'SkillDiv' + skillctr);
newTextBoxDiv.html('<label>Skill No. '+ skillctr + ' : </label>' +
'<input type="text" name="skill' + skillctr +
'" id="skill' + skillctr + '" value="" >');
newTextBoxDiv.appendTo("#SkillsBoxesGroup");
skillctr++;
});
so how can i save the generated fields in my table in database now?
how am i gonna declare the field in php like.. $_POST['skill'].
i need help here. please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用
name="skill' + Skillctr + '"
,使用name="skill[]"
。这样 PHP 将创建一个可以循环的数组:
Don't use
name="skill' + skillctr + '"
, usename="skill[]"
.That way PHP will helpfully create an array that you can loop though:
您只需确保使用该 javascript 添加的输入元素位于
You just need to make sure that the input elements you are adding with that javascript are inside a
<form>
. Then when you submit the form to a php page, you can access the values with$_POST
like you wrote above.