为什么这不适用于Internet Explorer? [jQuery,radio,selectors]

时间:2010-12-07 14:21:57

标签: javascript jquery internet-explorer jquery-selectors

我正在尝试调试在任何版本的Internet Explorer上都不起作用的内容。

以下是代码:

<div id="sondage">
    <input type="radio" name="reponse" value="oui" id="oui">
    <label for="oui">Oui</label>

    <input type="radio" name="reponse" value="non" id="non">
    <label for="non">Non</label>
</div>

<script type="text/javascript" charset="utf-8">
$(function(){

    $('#oui, #non').click(function(){
        reponse = $('input[name=reponse]:checked').val();
        sondage_id = <?php echo $sondage->id ?>;

        $.ajax({
            type: "GET",
            url: "<?php echo url_for('@sondage_repondre') ?>",
            data: "reponse="+reponse+"&id="+sondage_id,
            success: function(msg){
                resultat = msg.split('|');

                if (resultat[0] == "true") {
                    $('#sondage_message').html("<?php echo __('Merci.') ?>");
                } else {
                    $('#sondage_message').html("<?php echo __('Désolé, vous avez déjà voté pour ce sondage. Merci.') ?>");
                }
                $('#sondage').html(resultat[1]);
            }
        });

    });

});
</script>

错误发生在该行(reponse = $('input[name=reponse]:checked').val();)上。

你知道发生了什么吗?

谢谢!

编辑:提问:错误是:

Line 511, Char 7, Object doesn't support this property or method.

这是完整的输出:http://pastie.org/1355610

再次感谢!

1 个答案:

答案 0 :(得分:5)

你错过了var,应该是:

var reponse = $('input[name=reponse]:checked').val();

您的其他变量也是如此...总是使用var来声明它们,无论它们在何处,都不依赖于不总是允许的隐式全局定义。