学习笔记——文本框显示默认,点击后默认输入消失。鼠标离开后又出现

先看一下效果点击后然后是离开后

然后是代码,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta name="generator" content="editplus" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
 <style type="text/css">
</style>
 </head>

 <body>
  <input type="text" id="id1" value="please input cotent" onfocus="test1()" onblur="test2()">
 </body>
<script type="text/javascript">
function test1(){
var ff=document.getElementById("id1");
ff.value="";
}
function test2(){
var ffd=document.getElementById("id1");
ffd.value="please input cotent";
}
</script>
</html>

主要是通过聚焦失焦设置点击事件,然后通过设置value的值

posted on 2016-03-23 22:52  ShamSilence  阅读(275)  评论(0编辑  收藏  举报

导航