How to know if the text in a textbox is selected?
问题 I have text boxes <input type='text'> that only allow numeric characters and wont let the user enter a dot (.) more than once. Problem is, if the text in the text box is selected, the user intends to overwrite the contents with a dot, hence making it allowed! The question is, how can you tell in javascript whether the text in that text box is selected or not. Thanks 回答1: The following will tell you whether or not all of the text is selected within a text input in all major browsers. Example: