Javascript jQuery句柄按钮在窗体内单击
我不明白为什么我的jQuery代码无法访问表单中的按钮Javascript jQuery句柄按钮在窗体内单击,javascript,jquery,forms,function,click,Javascript,Jquery,Forms,Function,Click,我不明白为什么我的jQuery代码无法访问表单中的按钮 <form action=""> <div class="field"> <label for='username'>Insert username</label> <input type="text" id="username" name="username"> </div> <button type='
<form action="">
<div class="field">
<label for='username'>Insert username</label>
<input type="text" id="username" name="username">
</div>
<button type='submit' class='btn btn-lg btn-primary buttonRegister'>Register</button>
</form>
--------------或----------------------
$('.buttonRegister').click(function(){
//action inside function
});
$('.buttonRegister').on("click", function(){
//action inside function
});
--------------或----------------------
$('.buttonRegister').click(function(){
//action inside function
});
$('.buttonRegister').on("click", function(){
//action inside function
});
他们都没有工作。我确信click函数内部的代码是有效的,因为我尝试将按钮置于表单外部,效果很好。在其他任何操作之前,先将e.preventDefault()添加到表单内部
$('.buttonRegister').on("click", function(e){
e.preventDefault(); // <<-- required to stop the refresh
//action inside function
});
$('.buttonRegister')。在(“单击”,函数(e){
e、 preventDefault();//将e.preventDefault()添加到内部,然后再添加其他内容
$('.buttonRegister').on("click", function(e){
e.preventDefault(); // <<-- required to stop the refresh
//action inside function
});
$('.buttonRegister')。在(“单击”,函数(e){
e、 preventDefault();//将e.preventDefault()添加到内部,然后再添加其他内容
$('.buttonRegister').on("click", function(e){
e.preventDefault(); // <<-- required to stop the refresh
//action inside function
});
$('.buttonRegister')。在(“单击”,函数(e){
e、 preventDefault();//将e.preventDefault()添加到内部,然后再添加其他内容
$('.buttonRegister').on("click", function(e){
e.preventDefault(); // <<-- required to stop the refresh
//action inside function
});
$('.buttonRegister')。在(“单击”,函数(e){
e、 preventDefault();//因为表单提交,重新加载页面?您可能需要研究如何处理表单上的提交
。@adeneo我没有想到这一点,谢谢,我需要更改它,因为我需要不“刷新”的提交对于我的php页面也是如此。您的第二个代码看起来不错。将evt添加到函数args中,并在函数中执行evt.preventdefault(),因为表单提交,重新加载页面?您可能需要研究处理表单上的submit
。@adeneo我没有想到这一点,谢谢,我需要更改它,因为我需要提交而不需要“刷新”对于我的php页面也是如此。您的第二个代码看起来不错。将evt添加到函数args中,并在函数中执行evt.preventdefault(),因为表单提交,重新加载页面?您可能需要研究处理表单上的submit
。@adeneo我没有想到这一点,谢谢,我需要更改它,因为我需要提交而不需要“刷新”对于我的php页面也是如此。您的第二个代码看起来不错。将evt添加到函数args中,并在函数中执行evt.preventdefault(),因为表单提交,重新加载页面?您可能需要研究处理表单上的submit
。@adeneo我没有想到这一点,谢谢,我需要更改它,因为我需要提交而不需要“刷新”对于我的php页面也是如此。您的第二个代码看起来不错。将evt添加到函数args中,并在函数中执行evt.preventdefault()