开发者

Tab into a textarea not highlighting the text

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜