[英]ASP.NET MVC Submit button does not work on Chrome
The code below works perfectly on IE, but when used in Chrome, it doesn't work.下面的代码在 IE 上完美运行,但在 Chrome 中使用时,它不起作用。 When I checked in debug mode, it doesn't trigger the MVC controller (but in IE it does).
当我在调试模式下检查时,它不会触发 MVC 控制器(但在 IE 中会)。 Does anyone know how I can get this to work in Chrome?
有谁知道我如何让它在 Chrome 中工作?
<input type="submit" value="Create" id="btnSaveSubmit" name="btnSubmit" class="button" onclick="if (!($('#frID').valid())) { return false; } this.disabled = true; this.value = 'Saving...'" />
Your code is just pure html & Javascript, doesn't relate to mvc. 您的代码只是纯html和Javascript,与mvc无关。
Anyway, Chrome does not allow you to execute inline code. 无论如何,Chrome不允许您执行内联代码。 Inline JavaScript will not be executed
内联JavaScript将不会执行
Proper way to do: 正确的方法:
1)With javascript: Bind the event listener: 1)使用javascript:绑定事件监听器:
document.addEventListener('DOMContentLoaded', function() {
var btn = document.getElementById('btnSaveSubmit');
// onClick's logic below:
btn.addEventListener('click', function() {
if (!($('#frID').valid())){
return false;
}
this.disabled = true;
this.value = 'Saving...';
});
});
2) With Jquery: 2)使用Jquery:
$(document).ready(function() {
$("#btnSaveSubmit).on('click',function(){
if (!($('#frID').valid())){
return false;
}
this.disabled = true;
this.value = 'Saving...';
});
});
encountered this issue in Chrome as well.在 Chrome 中也遇到了这个问题。 The cause for me: I was disabling the submit button after it was being clicked.
我的原因:我在点击提交按钮后禁用了它。
For Chrome, but not other browsers, the click handler seems to fire before the submit handler.对于 Chrome,而不是其他浏览器,点击处理程序似乎在提交处理程序之前触发。 For that reason, I never got to back to the controller.
出于这个原因,我从来没有回到控制器。
The solution for me was to not disable the submit button at all after the user clicked it.我的解决方案是在用户单击提交按钮后根本不禁用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.