2013-04-22 3 views
0

У меня есть вложенное текстовое поле внутри элемента списка здесь radiobuttom это кодFirefox теряет фокус на вложенном текстовом поле

<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 вместо ASP, которые будут генерировать HTML и JavaScript. – Quentin

ответ

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

+0

Кстати, более короткая версия будет '$ (" # OtherEdNsgCertName "). Show(). Focus();' – Yeronimo

+0

вы знаете, почему это произошло только в firefox? – pita

Смежные вопросы