开发者

Simple javascript mouseout undo highlight text

I have always sucked at javascript I have read multiple books and studied online but on some things I just cannot get them to work. Anyway, I use a simple javascript function that selects all of the text in a textfield when I hover it:

<input type="text" onMouseOver="this.focus();this.select()">

how do I undo that action once the cursor is no longer over that field? This is important since I bought a new BlackBerry Bold 9930 and hate the internet browsing, but with javascript I am making things easier like highlighting all text in a field by just hovering over it. So I just need the code that unselects all of开发者_Go百科 the text once I move away from that field since in the Blackberry browser it wants to stay stuck in that field highlighting the text unless I click somewhere else. Thanks.


<input type="text" onMouseOver="this.focus();this.select()" onmouseout="this.selectionStart = this.value.length; this.blur();">

http://jsfiddle.net/meQek/

it's kind of an odd way but logical when you think about it. If you highlight it all on mouseenter, the selectionEnd is at the end... so just make the selectionStart at the same position on mouseleave.

EDIT:

actually... blur works just fine :P

http://jsfiddle.net/meQek/1

<input type="text" onMouseOver="this.focus();this.select()" onmouseout="this.blur();">


Try this:

<input type="text" onMouseOver="this.focus();this.select()" onmouseout="this.blur();">

Not sure how the Blackberry browser will handle it, but in most browsers it should unfocus the text field when your mouse leaves it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜