我在提交的表单中有一个对话框 div。div 由使用 JavaScript 动态填充的复选框填充。当我单击链接打开对话框时,选择几个复选框,关闭,提交,我的 PHP 进程页面没有将选定的复选框注册为 POST 项。
所以,我相信因为复选框是在页面加载后动态生成的,它们实际上并没有注册为表单中的元素?这个对吗?有了这些知识(或缺乏知识),我不知道如何规避这一点。
任何帮助将不胜感激,我四处寻找帮助无济于事。
HTML:
<form action="submit.php" method="POST">
<div id="dialog" style="font-size:14px;">
<div id="states_container">
<div style="width:33%; float:left;" id="col1">
</div>
<div style="width:33%; float: left;" id="col2">
</div>
<div style="width:33%; float: left;" id="col3">
</div>
</div>
</div>
<input type="submit" value="Submit">
</form>
submit.js(是的,我知道这是糟糕的代码,但我要重构):
$(function() {
$( "#dialog-link" ).click(function( event ) {
$( "#dialog" ).dialog( "open" );
event.preventDefault();
});
$( "#dialog" ).dialog({
autoOpen: false,
width: 600,
buttons: [
{
text: "Ok",
click: function() {
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
var states1 = {
AL: "Alabama",
AK: "Alaska",
AZ: "Arizona",
AR: "Arkansas",
CA: "California",
CO: "Colorado",
CT: "Connecticut",
DE: "Delaware",
DC: "District Of Columbia",
FL: "Florida",
GA: "Georgia",
HI: "Hawaii",
ID: "Idaho",
IL: "Illinois",
IN: "Indiana",
IA: "Iowa",
KS: "Kansas"
};
var states2 = {
KY: "Kentucky",
LA: "Louisiana",
ME: "Maine",
MD: "Maryland",
MA: "Massachusetts",
MI: "Michigan",
MN: "Minnesota",
MS: "Mississippi",
MO: "Missouri",
MT: "Montana",
NE: "Nebraska",
NV: "Nevada",
NH: "New Hampshire",
NJ: "New Jersey",
NM: "New Mexico",
NY: "New York",
NC: "North Carolina"
};
var states3 = {
ND: "North Dakota",
OH: "Ohio",
OK: "Oklahoma",
OR: "Oregon",
PA: "Pennsylvania",
RI: "Rhode Island",
SC: "South Carolina",
SD: "South Dakota",
TN: "Tennessee",
TX: "Texas",
UT: "Utah",
VT: "Vermont",
VA: "Virginia",
WA: "Washington",
WV: "West Virginia",
WI: "Wisconsin",
WY: "Wyoming"
};
$.each(states1, function(key, value) {
$('#col1').append(
'<label for="' + value + '"><input type="checkbox" name="'+value+'" id="'+value+'">'+value+'</label><br/>'
);
});
$.each(states2, function(key, value) {
$('#col2').append(
'<label for="' + value + '"><input type="checkbox" name="'+value+'" id="'+value+'">'+value+'</label><br/>'
);
});
$.each(states3, function(key, value) {
$('#col3').append(
'<label for="' + value + '"><input type="checkbox" name="'+value+'" id="'+value+'">'+value+'</label><br/>'
);
});
});