问候,
我遇到了以下问题:
点击“添加风味”按钮(参见完整的示例代码),动态生成一个下拉框,文本字段和两个复选框,每次执行按钮时都会执行。
有没有办法通过ajax将动态生成的(实际“附加”)元素的值添加到数据库?
这里是示例代码,我想在其中找到它
[代码]
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function addUsedComp(){
var id = document.getElementById("id").value;
$("#divFlav").append("<p id='row" + id + "'><label for='txt" + id + "'> Flavor " + id + " <select id='select'><option selected='selected'>Vanilla</option><option >Chocolate</option><option >Strawberry</option><option >Coconut</option></select> amount: <input name='val' type='text' size='8' /> <input type='checkbox' name='concentration1' value='gramm' id='id+1' />gramm<input type='checkbox' name='concentration2' value='percent' id='id' />percent <input name='Remove' type='button' value='Remove' onClick='removeSelectionField(\"#row" + id + "\"); return false;' /><p>");
id = (id-1)+2;
document.getElementById("id").value = id;
}
<!--function removes an selection field-->
function removeSelectionField(id) {
$(id).remove();
}
</script>
<!--ajax process/http process should get dynamically send all the data of each step, each time clicked on the "next step" button-->
</head>
<body>
<p><input name="Add" type="button" value="Add Flavor" onClick="addUsedComp(); return false;" /></p>
<form action="#" method="get" id="form1">
<input type="hidden" id="id" value="1">
<div id="divFlav"></div>
</body>
</html>
[/代码]
提前感谢您提供任何提示