sgk*_*nay -1 jquery input button
当我使用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'>
Run Code Online (Sandbox Code Playgroud)
是这样的:
$('.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? */
});
Run Code Online (Sandbox Code Playgroud)
提前致谢!
编辑
在这里/那里学到一些东西之后,找到了另一种简单的方法来做到这一点,有些人可能不同意,但它到目前为止有效:
<input style='width:65px;' type='button' class='Bags' id='Buy' name='".$idn."' value='Buy Bags' onclick='return false;'>
Run Code Online (Sandbox Code Playgroud)
通过添加" onClick ='返回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 :) )
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15300 次 |
| 最近记录: |