一段水印文字的练习

做淘宝登陆页面时登陆框的水印文字的需要,做了如下的练习。

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="..jqueryjquery-2.1.3.js" type="text/javascript" ></script>
<style type="text/css">
body,input
{
font-size:18px;
}
.graycss
{
color:#CCCCCC;

}
</style>
<script type="text/javascript">
$(function(){
$("#yourtelephone").keypress(function(e){
if ($(this).attr("inputflag")=="0"){
$(this).attr("inputflag","1");
$(this).val("").removeClass("graycss");

}
event.stopPropagation();
}).keydown(function(e){

if ($(this).attr("inputflag")!="0"){
if ($(this).val().length==0){

$(this).attr("inputflag","0");
$(this).val($(this).attr("telephone")).addClass("graycss");
return false;
}
}
else
{
if(e.key=="Backspace" || e.key=="Del"){return false;};
}
});
});

</script>
</head>
<body>
<form>
<h3>水印提示文字练习</h3>
手机号<input type="text" id="yourtelephone" class="graycss" telephone="输入手机号" inputflag="0" value="输入手机号" />
</form>
</body>

</html>

原文地址:https://www.cnblogs.com/shijia-dreamhome/p/4304024.html