如果我有这样的动态元素:http: //jsfiddle.net/kfm5b/2/
<select name="roomFac1" id="roomFac1">
<option selected="selected">Any</option>
</select>
<input type="button" value="Add" class="pmbtn" id="addFac"/>
<input type="button" value="Remove" class="pmbtn" id="removeFac"/>
$(document).ready(function(){
$('#addFac').click(function(){
var $objs = $('select[name*=roomFac]');
var n = $objs.size() + 1;
var $obj = $objs.first().clone();
$obj.attr('name', 'roomFac'+n).attr('id', 'roomFac'+n);
$obj.appendTo($('body'));
});
$('#removeFac').click(function(){
var $objs = $('select[name*=roomFac]');
if($objs.size() > 1){
$objs.last().remove();
}
});
});
一旦用户单击提交按钮,我将如何获取其输出以用于 AJAX 提交,例如
$("#submit").click(function () {
...
...
var dataString = ....; // how I would I implement the dynamically created elements here s I don't know the size
...
...
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
cache: false,
success: function (html) {
$('#search_room').html(html);
}
});
其次,我会在处理处理的 PHP 文档中放入什么?