我使用h:selectOneRadio標記。
我需要將光標焦點設置爲第一個無線電字段。如何設置光標焦點onload?
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h:form id="focusForm" >
<h:selectOneRadio id="testRadioId" value="">
<f:selectItem id="si1" itemLabel="JSF" />
<f:selectItem id="si2" itemLabel="JSP" />
</h:selectOneRadio>
</h:form>
</body></html></f:view>
這裏的火狐(瀏覽器)給ID:focusForm:testRadioId:0那場。
所以我用下面的腳本:
document.getElementById("focusForm:testRadioId:0").focus();
但是,
有些時候,我可以動態地改變從後臺bean禁用無線電領域。
<h:selectOneRadio id="testRadioId" value="">
<f:selectItem id="si1" itemLabel="JSF" itemDisabled="true"/>
<f:selectItem id="si2" itemLabel="JSP" />
</h:selectOneRadio>
所以這裏我禁用第一個單選按鈕。
現在,如果我使用相同的腳本,則不會將光標焦點設置爲第一個無線電領域。
如何處理?這意味着如何在onload期間動態地改變我的腳本?
請幫幫我。
在此先感謝。
更新:
感謝BaluC。
以下代碼有效。
<a4j:loadScript src="resource://jquery.js"/>
<script type="text/javascript">
function setFocusRadioField()
{
jQuery(':input:visible:enabled:first').focus();
}
</script>
<body onload="setFocusRadioField();">
</body>
下面的代碼
但沒有奏效。 我測試方式如下:
jQuery('#focusForm\:testRadioId:enabled:first').focus();
然後,
jQuery('#focusForm\\:testRadioId:enabled:first').focus();
然後,
var id = "#focusForm:testRadioId:enabled:first".replace(/:/g, "\\:");
jQuery(id).focus();
我不知道我做了錯誤。 更好,我需要使用id設置光標焦點。 在此先感謝。
感謝您的全力支持。現在我檢查它的第一個代碼。 [ID^=名]。它完美的工作。 – Eswar 2010-06-21 01:22:28
但在IE6,IE8中無法使用。 – Eswar 2010-06-21 01:58:40
$('[id^= focusForm:testRadioId]:enabled:first')。focus();它在FIreFox中工作。在IE6,IE8中沒有工作。 我沒有其他瀏覽器。我仍然不檢查任何其他瀏覽器。 – Eswar 2010-06-21 02:12:20