我想讓IE9知道單選按鈕組有一個選項選中,通過腳本設置。在我的腳本中,我想要檢查第一個選項。在xhtml文檔類型(必需配置)上打開兼容模式的IE9中不起作用。jquery 1.9不會檢查收音機在IE9/xhtml
var $list = jQuery("#my-radio-container");
jQuery(":radio",$list).each(function (ind,el) {
var $elm = jQuery(el);
$elm.addClass("ui-widget-content");
if (ind == 0) {
$elm.addClass("ui-state-active")
.get()[0].setAttribute("checked", "checked")
});
我已經嘗試了所有常用的連擊:
$elm.attr('checked', 'checked');
$elm.prop('checked', 'checked');
$elm.attr('checked', true);
以及更不尋常的:
$elm.get()[0].setAttribute("checked", "checked")
它看起來像它應該工作 - 如果你檢查的innerHTML $list
那麼它顯示對象中有CHECKED="checked"
,所以你會認爲它會被選中?但是,表單文章的perfoming表明沒有數據提交給單選按鈕(單擊按鈕,而不是將其設置爲腳本,顯示相同的外部html,並且該表單將隨該值一起發佈)。
恢復到這個甚至不工作,這是奇怪的:
document.forms[0].elements[jQuery(":radio",$list).filter(":first").attr("name")].value = jQuery(":radio",$list).filter(":first").attr("value");
// which works out like this:
document.forms[0].myradio.value="1";
- 我等到文件準備好。
- 我用Google搜索了這個。我一直在嘗試various在各種文章中提出的技術,並且僅僅因爲我只鏈接到一篇文章並不意味着我已經關閉了大約20個其他文章的標籤。
- 我檢查了我的元素是什麼,是的它是一個輸入類型=無線標籤,而不是它的標籤或愚蠢的東西。
IE9 doesn't want to let me set a radio button check state through code.
看起來像我的挫折我一直在使用.prop()不正確;正確的用法可以解決問題;乾杯! (和phew:我不需要使用隱藏域hack!) – frumbert 2013-02-14 02:31:39