2012-02-21 10 views
0

在IE8中,運行下面的代碼時,出現的警報沒有任何意義。有時會返回第一個按鈕,有時會返回另一個IE8選擇器或jQuery ButtonSet不一致地返回正確的結果(單選按鈕)

I asked a similar question to this on SO.也許這些是相同的問題。目前尚不清楚,所以我決定提出第二個問題。

This one is also related. And this one 但他們都通過足夠錯過了標記,我不知道現在該做什麼。

<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/south-street/jquery-ui.css" rel='stylesheet' type='text/css'> 

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.js"></script> 
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.11/jquery-ui.js"></script> 

<script language="javascript"> 

    $(document).ready(function() { 
     $("#toolGroup").buttonset(); 
     $("#toolGroup").click(
     function() { 
      alert($('input:radio[name=marker]:checked').val()); 
     } 
     ); 
    }); 

</script> 
</head> 
<body> 

    <div id="toolGroup"> 
     <input name="marker" type="radio" id="check1" value="tool1" checked /><label for="check1"><img src="/images/tool1.png" width="40" /></label> 
     <input name="marker" type="radio" id="check2" value="tool2" /><label for="check2"><img src="/images/tool2.png" width="40" /></label> 
     <input name="marker" type="radio" id="check3" value="tool3" /><label for="check3"><img src="/images/tool3.png" width="40" /></label> 
    </div> 

</body> 
</html> 

回答

0

因爲你綁定的click事件的容器,它越來越觸發,因爲你<label for='blah'>標籤的單選按鈕兩次。你可以通過這個替換您的函數看到這種情況出現:

$(document).ready(function() { 
    $("#toolGroup").click(function (e) { 
     alert(e.target); 
    }); 
}); 

嘗試結合自己的點擊事件的輸入來代替。當你點擊標籤時,它會觸發輸入上的點擊事件。所以,這樣的事情應該得到你想要的東西:

$(document).ready(function() { 
    $("#toolGroup").buttonset(); 
    $("#toolGroup input").click(function() { 
     alert($('input:radio[name=marker]:checked').val()); 
    }); 
}); 

我測試了IE8,它爲我工作結合到輸入端。

編輯:您還可以點擊替代品()的變化()

+0

回覆:變化 - 看看這一個http://stackoverflow.com/questions/9344663/jquery-1-7-1-buttonset -in-ie8-not-consistent-firing-the-change-event – 010110110101 2012-02-21 19:39:33

+0

適合我... http://jsfiddle.net/wcJcY/1/ – 2012-02-23 01:17:37

相關問題