我知道这方面存在很多问题,但我不知道该搜索什么.
我有一个电子邮件字段,我希望它有"在这里写你的电子邮件",当你点击/做onfocus它应该消失.虽然如果你没有写东西并且继续写它,它应该再次出现.
She*_*hef 10
<input id="email" name="email" type="text" value="Write your email here" />
Run Code Online (Sandbox Code Playgroud)
$('#email')
.on('focus', function(){
var $this = $(this);
if($this.val() == 'Write your email here'){
$this.val('');
}
})
.on('blur', function(){
var $this = $(this);
if($this.val() == ''){
$this.val('Write your email here');
}
});?
Run Code Online (Sandbox Code Playgroud)