通过ajaxCall
我动态创建了一个用户列表,每个用户以单独的形式处理版主操作。喜欢:
<form id="'.$aSpeler['playerID'].'">
<select name="aktieopspeler">
<option value="" disabled selected>Kies actie</option>
<option value="vakantiemodusIN">Vakantiemodus IN</option>
</select>
<input type="submit" value="OK">
</form>
我所有的表单都由jQuery Form插件(malsup)处理。我能想到的唯一解决方案也是为每个表单创建绑定,但是是否可以一次绑定所有表单?
我用于现有表单的代码:
var options = {
target:'#maincontent', // target element(s) to be updated with server response
url: 'backend/admin_speler.php', // override for form's 'action' attribute
type: 'post' // 'get' or 'post', override for form's 'method' attribute
};
// bind to the form's submit event
$('#frm_zoek_speler').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options);
return false;
});
使用: jQuery v2.1.3
您可以将单个事件绑定到元素父级,以达到所有所需的表单:
$("#parent").on('submit', 'form', function(){
$(this).ajaxSubmit(options);
return false;
});
如果您使用的是 1.7 之前的 jQuery 版本,则可以使用:
$("#parent").delegate('form', 'submit', function(){
$(this).ajaxSubmit(options);
return false;
});