如果文本区域为空,我想在文本区域添加“-”。目前,它可以与Firefox和Chrome完美配合,但是IE让我头疼。IE就像其他浏览器一样插入相同的内容,但之后会跳转到textarea的开头。
因此其他浏览器会像这样的“-c”,但IE是“ c-” // c = cursor
$('#textbox').focus(function(){
if(this.value == "") {
this.value = this.value + "- ";
}
});
您可以像这样明确地设置光标位置,
$('#textbox').focus(function() {
if (this.value == "") {
this.value = this.value + "- ";
this.setSelectionRange(1, 1);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句