简体   繁体   English

重点关注Textarea

[英]Textarea on focus

I am using the code below to try and get the value to show before clicking. 我正在使用下面的代码来尝试获取要显示的值,然后再单击。 I want the value "reply here" to show in the texarea and when someone clicks it should go away letting them type their reponse. 我希望值“在这里答复”显示在德克萨斯州,当有人单击时,它应该消失,让他们键入他们的答复。 I am using the code below but it doesn't show the value until one click in the box. 我正在使用下面的代码,但是直到在框中单击一下它才显示该值。 How can i tweak it? 我该如何调整?

    onclick="this.value='';" onfocus="this.select()" 
    onblur="this.value=!this.value?'Reply          
    here':this.value;" value="Reply here"

textarea的不采用“ value”属性,要设置textarea的默认值,请使用以下命令:

<textarea>reply here</textarea>

I'm searching for a different answer, but thought I could shine some light on what's available with HTML5. 我正在寻找不同的答案,但认为我可以对HTML5可用的内容有所了解。 All you need to do is do the following: 您所需要做的就是执行以下操作:

<textarea placeholder="Reply here"></textarea>

However, I'm sure it doesn't work with much older browsers, but here's a link to get backward compatibility: how to use HTML5 placeholder attribute with backward-compatibility in mind? 但是,我确定它不适用于许多较旧的浏览器,但这是获得向后兼容性的链接: 如何在考虑向后兼容性的情况下使用HTML5占位符属性?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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