문제

I am using jQuery to select and pop an alert when user click button. The below code works on 'standard' browsers (Chrome, Firefox, etc), but IE 6 fails.

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

Looks like jQuery selector of such input won't work in IE 6. How can I make it compatible for IE 6 as well?

도움이 되었습니까?

해결책

You can assign your buttons a class and then reference with that.

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

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

EDIT: this code works for me in 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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top