I've been working on sending text to an input element in Chrome and I noticed that, unlike in IE or FF, calling .focus() does not put the curs开发者_开发问答or in the text area. So does anyone know of an alternative for placing the cursor on a Chrome input element?
I have no issues either. Here is an simple HTML file I have that works in Chrome:
<html>
<body>
<textarea id="ta1"></textarea>
<br />
<textarea id="ta2"></textarea>
<br />
<textarea id="ta3"></textarea>
<script>
document.getElementById("ta2").focus();
</script>
</body>
</html>
Are you putting the script section above or below the textareas?
Here's some of the code I'm using:
var event = document.createEvent("HTMLEvents");
event.initEvent("focus", true, true);
element.dispatchEvent(event);
精彩评论