javascript – 如何从文本框中删除焦点?

前端之家收集整理的这篇文章主要介绍了javascript – 如何从文本框中删除焦点?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

打开窗体时,光标在文本框中等待帮助文本.因此,发生了一些验证错误.因此我不想在打开表单时使用焦点,用户必须单击文本并键入文本.但是文本框中的光标没有任何onfocus事件.

@H_301_5@if(!$.trim($("#productsTextArea1").val())){ helpTip = "help string ...."; $("#productsTextArea1").val(helpTip); $("#productsTextArea1").css("color","#999"); $("#productsTextArea1").click(function(event){ if($("#productsTextArea1").val().indexOf("Enter a return")>-1){ $("#productsTextArea1").css("color","black").val(""); } }); } else { $("#productsTextArea1").blur(); }

请指教…

JSFIDDLE

最佳答案
更新:

使用HTML5占位符属性,您不需要使用任何js.

@H_301_5@