我dynamic forms在一个网页中有多个,如下所示
<form name='login' id='login_1'>
<input type='text' name='username'/>
<input type='password' name='pwd'/>
<input type='submit' name='submit' id='submit_1' value='Login'/>
</form>
<form name='login' id='login_2'>
<input type='text' name='username'/>
<input type='password' name='pwd'/>
<input type='submit' name='submit' id='submit_2' value='Login'/>
</form>
.......
.......
Run Code Online (Sandbox Code Playgroud)
这里id's是动态的,假设用户以第二种形式输入数据并提交然后我需要将第二(仅)表单数据发送到服务器而不使用第三方jQuery plugins,这里我无法submit button id正确选择.
是否使用发送数据的安全过程serializeArray();,尤其是登录过程?
一种方法是附加一个函数$('form').submit()并将你的ajax POST放到那里的服务器代码中......
$('form').submit(function(){
var thisForm = $(this);
alert(thisForm.find("input[type=submit]").attr("id"));
// perform ajax call here
// $(ajax). ---
return false;
});
Run Code Online (Sandbox Code Playgroud)
这是一个演示 http://www.bootply.com/61682