猿问

ASP.NET MVC提交按钮在Chrome上不起作用

下面的代码可在IE上完美运行,但在Chrome中使用时将无法正常工作。当我在调试模式下检查时,它不会触发MVC控制器(但在IE中会触发)。有谁知道我如何才能在Chrome中使用它?

 <input type="submit" value="Create" id="btnSaveSubmit" name="btnSubmit" class="button" onclick="if (!($('#frID').valid())) { return false; } this.disabled = true; this.value = 'Saving...'" />


达令说
浏览 185回答 1
1回答

慕尼黑8549860

您的代码只是纯html和Javascript,与mvc无关。无论如何,Chrome不允许您执行内联代码。内联JavaScript将不会执行正确的方法:1)使用javascript:绑定事件监听器:document.addEventListener('DOMContentLoaded', function() {&nbsp; &nbsp; var btn = document.getElementById('btnSaveSubmit');&nbsp; &nbsp; // onClick's logic below:&nbsp; &nbsp; btn.addEventListener('click', function() {&nbsp; &nbsp; &nbsp; &nbsp; if (!($('#frID').valid())){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; this.disabled = true;&nbsp; &nbsp; &nbsp; &nbsp; this.value = 'Saving...';&nbsp; &nbsp; });});2)使用Jquery:$(document).ready(function() {&nbsp; &nbsp; $("#btnSaveSubmit).on('click',function(){&nbsp; &nbsp; &nbsp; &nbsp; if (!($('#frID').valid())){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; this.disabled = true;&nbsp; &nbsp; &nbsp; &nbsp; this.value = 'Saving...';&nbsp; &nbsp; });});
随时随地看视频慕课网APP
我要回答