jquery - 如何使用 jQuery 取消按钮的提交

当我使用 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/

相关文章:

image - 如何使用 htaccess 更改图像路径?

sql - 使用 ROWNUM 在 Oracle 中获取质数记录

macos - 如何在终端加载 I/O 套件驱动程序扩展?

iphone - 选择时 Xcode UITableView 行未突出显示

fortran - 大型阵列导致 OpenMP 崩溃

matlab - 将向量转置到三维

asp.net - Web API 可以将XML 转换成Json 吗?

opengl - 可以只在 opengl 中移动相机而不重绘场景吗?

php - 获取最近过去的星期六(上星期六)

python - 从嵌套函数中的封闭范围访问变量