开发者

Tab into a textarea not highlighting the text

开发者 https://www.devze.com 2023-03-16 10:08 出处:网络
Basically, when I tab through this form, for every input field the text is highlighted, but this doesn\'t happen for my textareas.Any help or ideas would be appreciated. I\'ve included my textarea 开发

Basically, when I tab through this form, for every input field the text is highlighted, but this doesn't happen for my textareas. Any help or ideas would be appreciated. I've included my textarea 开发者_开发问答html below just in case.

<textarea onblur="if(this.value==''){this.value='Embed Code'}" onclick="if(this.value=='Embed Code'){this.value=''}" name="post.code">Embed Code</textarea>


Use onfocus instead of onclick, as getting focus from tabbing does not dispatch a click event (so the onclick handler isn't called). Note that HTML5 has the placeholder attribute that will do what your script is doing.

To select the text in the textarea, add a handler for the focus event:

<textarea ... onfocus="this.select()" ...

Note that this may annoy users as they don't expect this to happen for textarea elements.

0

精彩评论

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

关注公众号