Reputation: 3582
my code is:
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
var textarea = document.createElement('textarea');
$(textarea).val("abc").select();
$(textarea).select();
$("body").append($(textarea));
});
</script>
</head>
<body>
</body>
</html>
this code can work in chrome and firefox,but don't work in IE9,who can help me,thanks!
UPDATE:
error on :
$(textarea).val("abc").select();
Upvotes: 3
Views: 1543
Reputation: 3829
You may have more luck if you move the .select() line to AFTER the append() line. Also, try $(textarea).focus().select();
instead. This works for me in IE8 at least - don't have IE9 handy.
edit: My approach would be something like
$(function(){
var textarea = document.createElement('textarea');
$(textarea).val("abc");
$("body").append($(textarea));
$(textarea).focus().select();
});
Upvotes: 1