Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 聚焦后IE跳转到文本区域的开始_Javascript_Jquery_Html_Internet Explorer_Textarea - Fatal编程技术网

Javascript 聚焦后IE跳转到文本区域的开始

Javascript 聚焦后IE跳转到文本区域的开始,javascript,jquery,html,internet-explorer,textarea,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.

如果textarea是空的,我想在它前面加“-”。目前,它与Firefox和Chrome完美结合,但IE让我头疼。IE和其他浏览器一样插入相同的内容,但之后它会跳转到textarea的开头

所以其他浏览器是这样的“-c”,但IE“c-”//c=cursor

Javascript
  • 我做错了什么

您可以这样明确地设置光标位置

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

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