IE重点关注后跳到textarea的开头

时间:2014-11-12 07:25:58

标签: javascript jquery html internet-explorer textarea

我想把" - "如果它是空的,请发短信给textarea。它目前与Firefox和Chrome完美配合,但IE让我很头疼。 IE就像其他浏览器一样插入它,但之后它会跳转到textarea的开头。

所以其他浏览器就是这样的" - c"但IE" c-" // c = cursor

的Javascript

$('#textbox').focus(function(){
    if(this.value == "") {
       this.value = this.value + "- ";
          }
});
  • 我做错了什么?

1 个答案:

答案 0 :(得分:0)

你可以像这样明确地设置光标位置,

$('#textbox').focus(function() {
    if (this.value == "") {
        this.value = this.value + "- ";
        this.setSelectionRange(1, 1);
    }
});

Fiddle

相关问题