简体   繁体   English

在IE8中使用jQuery取消选择模糊文本框

[英]Unselect textbox on blur with jQuery in IE8

I'm trying to have the default behavior of a form select (or highlight) the text when you tab to the next input. 当您选择下一个输入时,我正在尝试使用表单的默认行为选择(或突出显示)文本。 I've had to add the .select() function on my password form fields for this to work in IE8. 我必须在我的密码表单字段中添加.select()函数,以便在IE8中工作。 Is there an equivalent to the jquery .select() for deselecting text? 用于取消选择文本的jquery .select()是否等效?

       $("#MyTextBox").focus(function() {
            $(this).select();
        });

        $("#MyTextBox").blur(function() {
            // Deselect here
        });

Not that I am aware, however this ought to work for you: 不是我知道,但这应该对你有用:

$(this).val($(this).val());

Here you set the value of the field to itself. 在这里,您可以将字段的值设置为自身。 the cursor should automatically be put on the end. 光标应自动放在最后。

The posted answer by James Wiseman worked perfectly in IE8, but for me at least, didn't work in Firefox 3.6.x. James Wiseman发布的答案在IE8中完美运行,但至少对我来说,在Firefox 3.6.x中无效。

I appreciate that the original question is specific to IE8, however, to help out those searching for a single solution that works in FF and IE, I used the following code: 我很欣赏最初的问题是针对IE8的,但是,为了帮助那些搜索在FF和IE中运行的单一解决方案,我使用了以下代码:

var temptext = $(textbox).val();
$(textbox).val('');
$(textbox).val(temptext);

(where textbox is the textbox object to work with). (其中textbox是要使用的文本框对象)。

It uses the same theory as James Wiseman's solution, however, it adds the specific step of setting the textbox's text to a blank string prior to setting the textbox text back to the original string. 它使用与James Wiseman的解决方案相同的理论,但是,它在将文本框文本设置回原始字符串之前添加了将文本框的文本设置为空白字符串的特定步骤。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM