Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 为什么<;按钮类型=';按钮'&燃气轮机;触发回发?_Jquery_Html_Asp.net Mvc - Fatal编程技术网

Jquery 为什么<;按钮类型=';按钮'&燃气轮机;触发回发?

Jquery 为什么<;按钮类型=';按钮'&燃气轮机;触发回发?,jquery,html,asp.net-mvc,Jquery,Html,Asp.net Mvc,我在表单元素中有一个,它不会触发回发,这正是我想要的 我真正想要的是将一些jQuery脚本绑定到按钮上。但当我这么做的时候,点击按钮会导致回发 <input type="submit" class="btn btn-danger" id="btnProceed" value="Proceed" /> <button type="button" class="btn" id="btnCancel">Cancel</button> $('#btnCancel')

我在表单元素中有一个
,它不会触发回发,这正是我想要的

我真正想要的是将一些jQuery脚本绑定到按钮上。但当我这么做的时候,点击按钮会导致回发

<input type="submit" class="btn btn-danger" id="btnProceed" value="Proceed" />
<button type="button" class="btn" id="btnCancel">Cancel</button>

$('#btnCancel').click(function () {
    $('#btnProceed').prop('disabled', 'true');
    $('#msg').css('display', 'inline');
    this.disabled = true;
    return false;
});

取消
$('#btnCancel')。单击(函数(){
$('btnproced').prop('disabled','true');
$('#msg').css('display','inline');
this.disabled=true;
返回false;
});
这就是它的工作原理吗?如何防止回发(不将按钮移到表单外部)?

试试这个

$('#btnCancel').click(function (event) {
    event.preventDefault();
    $('#btnProceed').prop('disabled', 'true');
    $('#msg').css('display', 'inline');
    this.disabled = true;
    return false;
});
还有,试试看

   <input type="button" class="btn" id="btnCancel">Cancel</input>
取消

请尝试以下代码

<input type="submit" class="btn btn-danger" id="btnProceed" value="Proceed" />
<input type="button" class="btn" id="btnCancel">Cancel</button>
$('#btnCancel').on('click',function () {
$('#btnProceed').prop('disabled', 'true');
$('#msg').css('display', 'inline');
this.disabled = false;
return false;
});

取消
$('btnCancel')。在('click',函数(){
$('btnproced').prop('disabled','true');
$('#msg').css('display','inline');
this.disabled=false;
返回false;
});

您的表单中是否有其他提交按钮?表单的共享代码是,BTNProced是提交按钮。在我将jQuery脚本绑定到btnCancel之前,单击它时没有回发。是否确实调用了单击处理程序?尝试在单击处理程序中添加日志/警报语句,然后查看是。这两个按钮被禁用,显示消息div,然后返回。但是,如果我删除了jQuery代码,单击“取消”按钮不会执行任何操作,也不会导致回发。请为其指定一个
name
属性,而不是
submit
。如果您可以编辑您的答案,并解释您显示的代码的作用,以及该代码回答问题的原因/方式,这将使您的答案更加有用。
this.disabled = false;
<input type="submit" class="btn btn-danger" id="btnProceed" value="Proceed" />
<input type="button" class="btn" id="btnCancel">Cancel</button>
$('#btnCancel').on('click',function () {
$('#btnProceed').prop('disabled', 'true');
$('#msg').css('display', 'inline');
this.disabled = false;
return false;
});