简单绑定在jQuery中无法在IE中用于单选按钮

时间:2010-03-19 04:40:56

标签: jquery cross-browser

嗨,这在Firefox中运行良好,但不适用于IE。我究竟做错了什么?感谢您的帮助!

$(document).ready(function(){
  $("#radiodiv").buttonset();
  $('#radio1').bind("click", function() {
     alert('Hello');
   });
}

<form>
 <div id="radiodiv">
  <input type="radio" id="radio1" name="radio" checked="checked"  /><label for="radio1">WaveHeight</label>
  <input type="radio" id="radio2" name="radio" /><label for="radio2">Current</label>
  <input type="radio" id="radio3" name="radio" /><label for="radio3">WaveHeightDir</label>
 </div>
</form>

2 个答案:

答案 0 :(得分:2)

您的JavaScript代码中存在语法错误:

$(document).ready(function(){
  $("#radiodiv").buttonset();
  $('#radio1').bind("click", function() {
     alert('Hello');
   });
}

应该使用closestache})然后用括号())然后用分号(;)关闭,如下所示:

$(document).ready(function(){
  $("#radiodiv").buttonset();
  $('#radio1').bind("click", function() {
     alert('Hello');
   });
});

使用像FireBug这样的网络调试工具和一个具有良好语法高亮度的编辑器可以帮助您轻松捕获这些语法错误。

答案 1 :(得分:0)

我一直有同样的问题。看起来当你在radiobutton组上使用buttonset时,点击并更改事件不会触发。我注意到抓住标签上的事件工作正常。

<div id="buttonGroup1" class='demo'>
                        <input  type="radio" id="radio1" name="radio" /><label for="radio1" class='tabButton'>Top 10 FAQ's</label>
                        <input  type="radio" id="radio2" name="radio" /><label for="radio2" class='tabButton'>Last 30 Days</label>
    </div>

$('。tabButton')。click(function(){                 警报( '你好');             });