jQuery click()事件没有触发

时间:2014-06-24 16:53:31

标签: javascript jquery

我对此代码存在一些问题:

    <script type="text/javascript" language="javascript">
        $(document).ready(function(){
            $( "#continue" ).click(function() {
            var c = $('[name="recaptcha_challenge_field"]').attr('name');
            var r = $('[name="recaptcha_response_field"]').attr('name');
            alert( "c=" + c );
            alert( "r=" + r );
            });
        });
    </script>

单击标识为continue的按钮时,警报框不会显示。我的代码有问题吗?

2 个答案:

答案 0 :(得分:3)

您没有用于文档就绪的结束函数包装器。所以它应该是:

<script type="text/javascript" language="javascript">
$(document).ready(function(){
    $( "#continue" ).click(function() {
        var c = $('[name="recaptcha_challenge_field"]').attr('name');
        var r = $('[name="recaptcha_response_field"]').attr('name');
        alert( "c=" + c );
        alert( "r=" + r );
    });
});

答案 1 :(得分:1)

你错过了一个clossing })

$(document).ready(function(){
    $( "#continue" ).click(function() {
        var c = $('[name="recaptcha_challenge_field"]').attr('name');
        var r = $('[name="recaptcha_response_field"]').attr('name');
        alert( "c=" + c );
        alert( "r=" + r );
    });
}); // <<<<<==== THIS IS MISSING