当我使用 jQuery UI 输入功能时,单击按钮后,它会提交/刷新整个网页。如何停止/取消整个网络重新加载?
<input style='width:65px;' type='button' class='ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all Bags' id='Buy' name='".$idn."' value='Buy Bags'>
是不是像:
$('.Bags').click(function(){
var $a = $(this).val();
var $b = $(this).attr('id');
var $c = $(this).attr('name');
/* input/button is the issue, how do i stop the form from refreshing? */
});
提前致谢!
编辑
在这里/那里学习了一些东西之后,找到了另一种简单的方法来做到这一点,虽然有些人可能不同意,但到目前为止它是有效的:
<input style='width:65px;' type='button' class='Bags' id='Buy' name='".$idn."' value='Buy Bags' onclick='return false;'>
通过添加“onClick='return false;'”将停止刷新/重新加载表单。
最佳答案
假设 .Bags 具有提交操作(在您的情况下它没有,因此不需要 preventDefault:
$('.Bags').click(function(e){
var $a = $(this).val();
var $b = $(this).attr('id');
var $c = $(this).attr('name');
.ajax(blah blah blah); (this one I know - input/button is the issue)
e.preventDefault(); // prevents default
return false; // also prvents default (i like to add both but just the e.preventDefault is required :) )
});
https://stackoverflow.com/questions/9448252/