English 中文(简体)
• 如何将治疗器的重点放在载荷上?
原标题:How to set cursor focus onload?

I use h:selectOneRadio tag.
I need to set the cursor focus to first radio field.

<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>

here The Firefox (browser) assign id :focusForm:testRadioId:0 that field.
So i use the following script:

document.getElementById("focusForm:testRadioId:0").focus();

But,
Some times, i may change dynamically disable the radio field from backing bean.

<h:selectOneRadio id="testRadioId" value="">
                 <f:selectItem id="si1" itemLabel="JSF" itemDisabled="true"/>
                 <f:selectItem id="si2" itemLabel="JSP" />
</h:selectOneRadio>

So here i disable the first radio button.
Now, If i use the same script, then not set cursor focus to first radio field.
how to handle this? that means how to alter my script dynamically during onload?

Please help me.
Thanks in advance.


<>Update:

感谢BaluC。

以下守则是有效的。

 <a4j:loadScript src="resource://jquery.js"/>
 <script type="text/javascript">   
         function setFocusRadioField()
         {
              jQuery( :input:visible:enabled:first ).focus(); 
          }
 </script>

<body onload="setFocusRadioField();">
</body>

But the following code is not worked. I test the following way:

jQuery( #focusForm:testRadioId:enabled:first ).focus();

然后,

jQuery( #focusForm\:testRadioId:enabled:first ).focus();

然后,

var id = "#focusForm:testRadioId:enabled:first".replace(/:/g, "\:");
jQuery(id).focus();

I don t know where i make the error. Better, I need set the cursor focus using id. Thanks in advance.

最佳回答

由于你gged笑了 j,这里的解决办法是:

$( [id^=focusForm:testRadioId]:enabled:first ).focus();

<代码>[id^= 姓名] 选任人将自姓名代码<> 姓名/代码>起的所有内容退回。

如果你的意图实际上是为了把首个非隐蔽和不可处置的投入内容集中起来,而不管投入类型如何,那么就使用:

$( :input:visible:enabled:first ).focus();
问题回答

我倾向于为此使用 j。 静坐在超文本体内。 界定 j字功能,或至少先从 body体上传。 因此,如果你重新在超文本档案中界定这一功能,就早就这样做。

传真:

<body onload=formFocus()>

Java:

<script type="text/javascript">        
    function formFocus()
    {
        focusForm.si1.focus();
    }
</script>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签