当用户单击文本输入控件时,我试图清除文本,如下所示,但它没有发生......下面是代码
var generate_message = $("<textarea onclick='if (this.value == 'Enter message here...') this.value = ''' rows='5' cols='45' id='comment'>Enter message here...</textarea>");
当用户单击文本输入控件时,我试图清除文本,如下所示,但它没有发生......下面是代码
var generate_message = $("<textarea onclick='if (this.value == 'Enter message here...') this.value = ''' rows='5' cols='45' id='comment'>Enter message here...</textarea>");
You cannot use single quote in html and javascript. It causes confusion in browser renderer
Usually, I separate the use of single quote and double quote. I use double quote for html and single quote for javascript
See example below
<textarea onclick="if (this.value == 'Enter message here...') this.value = ''" rows="5" cols="45" id="comment">Enter message here...</textarea>
See Fiddle example
see updated fiddle here
我想以不引人注目的方式做到这一点
$(function(){
$(document).on("focus","#comment",function(){
if($(this).val()=="Enter message here...")
$(this).val("")
});
});