0

当用户单击按钮时,我正在使用 jQuery 选择并弹出警报。以下代码适用于“标准”浏览器(Chrome、Firefox 等),但 IE 6 失败。

$('input[type="submit"]').click(function(event) {event.preventDefault();});
$('input[type="submit"]').click(function() {alert('hi')});

看起来这种输入的 jQuery 选择器在 IE 6 中不起作用。如何使它也与 IE 6 兼容?

4

1 回答 1

0

您可以为您的按钮分配一个类,然后引用它。

<input type="submit" class="runthis" />

$(".runthis").click(function() { });

编辑:此代码在 IE6 中适用于我:

<!doctype html>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            $("input[type='submit']").click(function() {

                alert("HI");
            });
        });
    </script>
</head>
<body>
    <form>
        <input type="submit" />
    </form>
</body>
</html>
于 2012-11-08T18:28:13.630 回答