Sto tentando di scrivere una JQuery per mettere a fuoco la prima casella di testo o area di testo visibile nel visibile nella casella di testo quando si carica una pagina. Nell'esempio seguente, concentrarsi sull'input text2 in form2.JQuery si concentra sulla prima casella di testo o area di testo quando la pagina viene caricata
La soluzione proposta in jQuery Dynamically focus on the first INPUT or Textarea non funziona per me.
Si prega di notare che abbiamo più pagine nella nostra applicazione. In alcune pagine il primo campo del modulo è una casella di testo e in altre pagine il primo campo è una textarea. Voglio scrivere un metodo JQuery che farà il lavoro per tutte le pagine indipendentemente dal fatto che il primo campo sia una casella di testo o un'area di testo. Nell'esempio seguente, la soluzione dovrebbe funzionare se si scambiano i campi textarea1 e text2.
<div id="header">
<form name="form1">
<input type="text" name="text1">
</form>
</div>
<div id="content">
<form name="form2">
<input type="checkbox" name="chc" value="test"><br>
<input type="hidden" name="hide">
<input type="text" name="text2"><br>
<textarea name="textarea1"></textarea><br>
<input type="text" name="text3">
</form>
</div>
Questo è quello che ho provato finora ...
// throws the error - $("#content input:text, #content textarea").first is not a function
$("#content input:text, #content textarea").first().focus();
// focuses on the textarea even if a text box is the first element in the form
$("#content textarea, #content[type='text']:visible:enabled:first").focus();
// focuses on the last text box in the page!
$("#content :input[type='text'], :textarea:visible:enabled:first").focus();
// focuses on the first text box even if a textarea is the first element in the form
$("#content :input[type='text']:visible:enabled:first, :textarea:visible:enabled:first").focus();
// focuses on the checkbox as it is the first input element
$('#content :input:visible:enabled:first').focus();
Grazie.
Grazie Adam! Questo ha funzionato. – neo108
In qualsiasi momento @ neo108:] –