Skip to main content
 首页 » 编程设计

jquery之$ ("#MyForm").submit(function () { 在 IE8 中不起作用,但在 FireFox 8 中不起作用

2026年07月28日6www_RR

$(document).ready(function () { 
    $("#MyForm").submit(function () { 
        alert("Hello"); 
        return true; 
    }); 
}); 

嗨,我上面有一个非常简单的代码,当我在 IE8 中提交表单时没有任何反应,但它在 FireFox 8 中工作正常。

我使用的是 jQuery 1.5.1。那么这是旧版本 jQuery 的问题吗?

请您参考如下方法:

我以前在 IE8 和 IE7 中见过这个。解决方法:

$("#MyForm").submit(function () { 
    alert("Hello"); 
    return true; 
}); 
 
// change input type to whatever submits the form 
$("#MyForm input[type='submit']").click(function(e) { 
    e.preventDefault(); 
    $(this).closest("form").submit(); 
});