I click a span, an input text is created with autofocus attribute (I also tried with autofocus="focus").

on Chrome, Opera, Safari, and even IE, the input text take the autofocus but only Firefox doesn't take it (I tested on FF V 16 and 18)

I had to make the fallback for the other browsers anyway so I added th focus via jQuery, but still, FF wouldn't take it after the input is created.

That's how I added it via jQuery:

<span onclick=" createdTextInput('idOffline','edit'); 
$(function(){ $('#idOfCreatedInput').focus(); });" title=""> clickMe </span>

I'm calling focus() on the the new created Input after creating it.

I even tried with selectors like:

 $(function() {$('[autofocus]').focus()});

and

 $('input[type="text"]').focus();
有帮助吗?

解决方案 2

I fixed it with a setTimeout() and selector on autofocus since with the input ID it didn't work..

setTimeout(function() {
  $("[autofocus]").focus(); 
}, 0);

其他提示

Try this:

$('#idOfCreatedInput').trigger('focus')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top