bra*_*age 2 jquery label input
我的"标签"在输入内部,所以我想在用户点击时清空该字段,如果它为空则"标签"再次返回
$('#name').focus(function() {
if ($(this).val()=="Your name") { $(this).val(""); }
}).blur(function() {
if ($(this).val()=="") { $(this).val("Your name") }
});
Run Code Online (Sandbox Code Playgroud)
这将是3个或更多领域,有更好的aprouch?不使用插件,只是jquery
我认为你的方法可能几乎和它一样简洁,但值得注意的是html5为标签提供了placeholder属性input:
<input type="text" placeholder="Your name." />
Run Code Online (Sandbox Code Playgroud)
当然,这还是要进入非现代浏览器......