Javascript Internet Explorer 8获取单选按钮的值

Javascript Internet Explorer 8获取单选按钮的值,javascript,jquery,internet-explorer,internet-explorer-8,Javascript,Jquery,Internet Explorer,Internet Explorer 8,我已经用谷歌搜索了大约2个小时来修复以下问题(包括其他Stackoverflow问题): 我认为这可能是一个时间问题,但试图用setTimeout延迟我的单个警报呼叫没有帮助 提前感谢各位,我希望我只是瞎了眼,没有在IE8中发现另一个丑陋的行为。我会在回调中使用最新的jQuery和选择器: jQuery(document).ready(function() { jQuery('input[type="radio"]').on(function('change blur mousedown

我已经用谷歌搜索了大约2个小时来修复以下问题(包括其他Stackoverflow问题):

我认为这可能是一个时间问题,但试图用setTimeout延迟我的单个警报呼叫没有帮助


提前感谢各位,我希望我只是瞎了眼,没有在IE8中发现另一个丑陋的行为。

我会在回调中使用最新的jQuery和选择器:

jQuery(document).ready(function() {
    jQuery('input[type="radio"]').on(function('change blur mousedown click') {
         alert(jQuery('input[type="radio"]:checked').val());
    });
});
实际上,这有点棘手,您无法在回调中使用“this”获取所选单选按钮,您必须使用其他选择器:
谢谢你的回答,但没有一个有效。我不确定这是jQuery中的一个bug,还是我在特定情况下遇到的一个问题。jQuery似乎在迫使IE8在字段真正更改之前触发更改事件

我最终通过绑定到blur事件并将其与powtacs:checked解决方案相结合来解决它,如下所示:

<script type="text/javascript">
jQuery(document).ready(function() {

   jQuery('input[type="radio"]').unbind('click.preset')
   .bind('click.preset', function() {
       jQuery(this).blur();
   }

   jQuery('input[type="radio"]').unbind('blur.preset')
   .bind('blur.preset', function() {
        doingStuffWith(jQuery('input[type="radio"]:checked').val());
    });
});
</script>

jQuery(文档).ready(函数(){
jQuery('input[type=“radio”]”)。解除绑定('click.preset'))
.bind('click.preset',function(){
jQuery(this.blur();
}
jQuery('input[type=“radio”]”)。解除绑定('blur.preset'))
.bind('blur.preset',function(){
doingStuffWith(jQuery('input[type=“radio”]:checked').val());
});
});

IE8的一个公平选项是在每个单选选项中创建一个类(!),并使用它来选择选中的选项。从语义上讲,这有点奇怪,但对我来说非常有效:

HTML


帮助我了解为什么不仅仅是:
jQuery('input[type=“radio”]').on('change',function(){doingstufwith(jQuery(this.val());});
IE中的更改侦听器在控件失去焦点时启动,这符合W3C规范,但不是直观的,也不是其他浏览器实现它的方式(他们有效地将其用作复选框和单选按钮的单击侦听器)。因此,通常在这些元素上使用单击侦听器。我可能错了,但我相信如果您在上的
中包含更改并单击,它将在某些浏览器上触发两次。
jQuery(document).ready(function() {
    jQuery('input[type="radio"]').on(function('change blur mousedown click') {
         alert(jQuery('input[type="radio"]:checked').val());
    });
});
<script type="text/javascript">
jQuery(document).ready(function() {

   jQuery('input[type="radio"]').unbind('click.preset')
   .bind('click.preset', function() {
       jQuery(this).blur();
   }

   jQuery('input[type="radio"]').unbind('blur.preset')
   .bind('blur.preset', function() {
        doingStuffWith(jQuery('input[type="radio"]:checked').val());
    });
});
</script>
<input type="radio" name="example" class="example_class" value="1"/>#1
<input type="radio" name="example" class="example_class" value="2"/>#2
<input type="radio" name="example" class="example_class" value="3"/>#3
var exampleValue = $('.example_class:checked').val();