使用javascript取消选择文本框的内容 [英] Deselect contents of a textbox with javascript
问题描述
我知道,通过javascript,您可以使用以下代码(在jQuery中)选择文本框的内容:
I understand that with javascript you can select the contents of a textbox with the following code (in jQuery):
$("#txt1").select();
有没有办法做相反的事情?要取消选择文本框的内容?我有一系列文本框的焦点事件设置为选择其中的内容。现在有几次,我想要专注于特定的文本框,而不选择它。我正在计划做的是调用这个特定文本框的焦点事件,但是随后通过一个调用来取消选择它。
Is there a way to do the opposite? To deselect the content of a textbox? I have the focus event of a series of textboxes set to select the contents within them. There are times now that I want to focus a particular textbox WITHOUT selecting it. What I am planning on doing is calling the focus event for this particular textbox, but then follow it with a call to deselect it.
$("input[type=text]").focus(function() {
$(this).select();
});
//code....
$("#txt1").focus();
//some code here to deselect the contents of this textbox
任何想法?
谢谢!
推荐答案
p($($($)
what about this:
$("input").focus(function(){
this.selectionStart = this.selectionEnd = -1;
});
这篇关于使用javascript取消选择文本框的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!