2013-12-19 32 views
-1

我有這樣的代碼:如何將焦點設置在一個領域裏面的形式

<script> 
      function teste() { 
       $("#firstname").focus(); 
      } 
      ; 
     </script> 
     <br/> 
     <hr/> 
     <h:form id="form"> 
      <p:panel header="New User" id="pnl"> 
       <h:panelGrid columns="2"> 
        <p:outputLabel for="firstname" value="Firstname: *" /> 
        <p:inputText id="firstname" required="true" /> 

        <p:outputLabel for="surname" value="Surname: *" /> 
        <p:inputText id="surname" required="true" onclick="teste();" /> 
       </h:panelGrid> 
      </p:panel> 

      <p:commandButton value="Submit" update="pnl" oncomplete="teste();"/> 
      <br/> 
     </h:form> 

我想一個動作的執行後設置一個場上的焦點,但是當組件的形式存在,它不起作用。當我刪除表單組件時,焦點工作。問題是我需要關注。 任何人都知道如何解決和/或因爲它?

+0

我不明白你的意思。「但是,當組件的形式存在,但它確實九月當我刪除了表單組件,重點工程的問題是我需要關注「???你需要關注什麼? –

+0

但是當組件形式存在時,它不起作用。抱歉 –

回答

0

h:formUINamingContainer,所以它的ID被預先添加到裏面的元素中。請嘗試以下操作:

function teste() { 
    $("#form\\:firstname").focus(); 
} 
0

由於正確的答案表明,該h:formUINamingContainer

這裏還有一個內置的方法

function teste() { 
    PrimeFaces.focus('form:firstname'); 
} 
相關問題