jQuery .val()Internet Explorer [英] jQuery .val() Internet Explorer
本文介绍了jQuery .val()Internet Explorer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在IE中测试以下脚本时,单击input
后,光标将移至输入的开头.
When I test script below in IE, after click on input
the cursor moves to the begining of the input.
[texttext{I click here}ext ] --> [{cursor goes here after click}texttextxt ]
$(".chrome-input").focus(function (){
$(this).val("test");
});
推荐答案
这将在输入获得焦点后将光标设置到末尾.
This will set the cursor to the end after input gets focus.
$('input').focus(function() {
$(this).val('test');
window.o = this;
if (o.setSelectionRange) /* DOM */
setTimeout('o.setSelectionRange(o.value.length,o.value.length)', 2);
else if (o.createTextRange) /* IE */
{
var r = o.createTextRange();
r.moveStart('character', o.value.length);
r.select();
}
});
这篇关于jQuery .val()Internet Explorer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文