本来这个小玩意很简单,不用记录到博客里,但今天是娱乐日,要快落一天,为了减轻负罪感,假装自己又学了点新东西
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css">
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<input type="text" placeholder="请输入地址"><!--placeholder并不能在输入框获得聚焦后自动消失-->
<br>
<input type="text" id="address" value="请输入邮箱地址">
<br>
<input type="text" id="password" value="请输入密码" ss="qq">
<script>
var test = document.getElementById("password");
console.log(test.getAttribute("ss"));//可以获取自定义特性欸
$("#address").focus(function(){
var text_value = $(this).val();
if(text_value == "请输入邮箱地址"){
$(this).val("");
}
});
$("#address").blur(function(){
var text_value = $(this).val();
if(text_value == ""){
text_val("请输入邮箱地址");
}
});
//密码框同理
</script>
</body>
</html>