简体   繁体   中英

.select() works with first click , not on second click.

im using a simple js method to select all text

onmouseup="(this).select();

it is working fine on first click but when i click it second time its not working

here is my code part:

<TEXTAREA type="text" onmouseup="(this).select();"  value="click me to autoselect" id="textBox" spellcheck="false" readonly ></TEXTAREA>

i mean that it is only working on first,third,fifth ..... click

not on second,fourth,sixth.... click //sometimes

here is a jsfiddle example you can try here what want to tell you. http://jsfiddle.net/wjb3me3k/

//working on chrome

please answer in javascript , im not familiar with jquery. thankyou.

The default browser behavior when you click on a text input is to position the cursor where you clicked. As a result of that, the selection is undone.

Replace

(this).select();

with

(this).select(); return false;

Returning false from a handler suppresses the browser's default behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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