2013-04-22 37 views
0

我有一個radiobuttom列表項 這裏內嵌套的文本框是代碼火狐失去重心的嵌套文本框

<asp:RadioButtonList ID="OtherEducInNursing" runat="server" RepeatColumns="1" RepeatDirection="Vertical" RepeatLayout="Table"> 
      <asp:ListItem Value="1">Certificate<input id="OtherEdNsgCertName" type="text" MaxLength="25"/></asp:ListItem> 
      <asp:ListItem Value="2">Baccalaureate</asp:ListItem> 
      <asp:ListItem Value="3">Master</asp:ListItem> 
      <asp:ListItem Value="4">Doctorate</asp:ListItem> 
      <asp:ListItem Value="5">None of the above</asp:ListItem></asp:RadioButtonList> 

它正常工作,無論是在鉻,但在Firefox中,當我試圖點擊文本框,閃爍的光標失去焦點,我不得不單擊文本框幾次讓光標回到

我說這樣

onclick="document.getElementById('OtherEdNsgCertName').focus();" 

仍然沒有一些代碼工作,沒有人知道爲什麼以及如何解決它?非常感謝

編輯 這裏是jQuery代碼太

$(document).ready(function() { 
    if($("#<%=OtherEducInNursing.ClientID%> :checked").val()!="1") 
      $("#OtherEdNsgCertName").hide(); 
     else 
      $("#OtherEdNsgCertName").show(); 
    $("#<%=OtherEducInNursing.ClientID%>").click(function() { 
     if($("#<%=OtherEducInNursing.ClientID%> :checked").val()!="1") 
      $("#OtherEdNsgCertName").hide(); 
     else 
      $("#OtherEdNsgCertName").show(); 
    }); 

編輯: 的html代碼:

<table id="MainPlaceHolder_OtherEducation_OtherEducInNursing"> 
<tbody><tr> 
    <td><input type="radio" value="1" name="ctl00$MainPlaceHolder$OtherEducation$OtherEducInNursing" id="MainPlaceHolder_OtherEducation_OtherEducInNursing_0"><label for="MainPlaceHolder_OtherEducation_OtherEducInNursing_0">Certificate<input type="text" onclick="document.getElementById('OtherEdNsgCertName').focus();" maxlength="25" id="OtherEdNsgCertName"></label></td> 
</tr><tr> 
    <td><input type="radio" value="2" name="ctl00$MainPlaceHolder$OtherEducation$OtherEducInNursing" id="MainPlaceHolder_OtherEducation_OtherEducInNursing_1"><label for="MainPlaceHolder_OtherEducation_OtherEducInNursing_1">Baccalaureate</label></td> 
</tr><tr> 
    <td><input type="radio" value="3" name="ctl00$MainPlaceHolder$OtherEducation$OtherEducInNursing" id="MainPlaceHolder_OtherEducation_OtherEducInNursing_2"><label for="MainPlaceHolder_OtherEducation_OtherEducInNursing_2">Master</label></td> 
</tr><tr> 
    <td><input type="radio" value="4" name="ctl00$MainPlaceHolder$OtherEducation$OtherEducInNursing" id="MainPlaceHolder_OtherEducation_OtherEducInNursing_3"><label for="MainPlaceHolder_OtherEducation_OtherEducInNursing_3">Doctorate</label></td> 
</tr><tr> 
    <td><input type="radio" value="5" name="ctl00$MainPlaceHolder$OtherEducation$OtherEducInNursing" id="MainPlaceHolder_OtherEducation_OtherEducInNursing_4"><label for="MainPlaceHolder_OtherEducation_OtherEducInNursing_4">None of the above</label></td> 
</tr> 

+0

如果您向我們展示了HTML和JavaScript,而不是生成HTML和JavaScript的ASP,將會更容易看到發生了什麼。 – Quentin 2013-04-22 13:38:47

回答

0

從文本框中取出對焦功能,並給予重點你的jQuery:

$(document).ready(function() { 
    if($("#<%=OtherEducInNursing.ClientID%> :checked").val()!="1") 
     $("#OtherEdNsgCertName").hide(); 
    else 
     { 
      $("#OtherEdNsgCertName").show(); 
      $("#OtherEdNsgCertName").focus(); 
     } 
$("#<%=OtherEducInNursing.ClientID%>").click(function() { 
    if($("#<%=OtherEducInNursing.ClientID%> :checked").val()!="1") 
     $("#OtherEdNsgCertName").hide(); 
    else 
     { 
      $("#OtherEdNsgCertName").show(); 
      $("#OtherEdNsgCertName").focus(); 
     } 

}); 
+0

它的工作原理,謝謝 – pita 2013-04-22 18:46:46

+0

順便說一句,較短的版本會'$(「#OtherEdNsgCertName」)。show()。focus();' – Yeronimo 2013-04-23 07:29:07

+0

你知道爲什麼這隻發生在Firefox嗎? – pita 2013-04-23 14:18:40