使用onfocus实现输入框的placeholder

来源:互联网 发布:啥软件下种子 编辑:程序博客网 时间:2024/03/29 13:20

<!DOCTYPE html>

<html>

<head>

<metacharset="UTF-8">

<title></title>

</head>

<body>

<inputtype="text" id="txt1" value="用户名"/>

<inputtype="text" name="txt2" id="txt2"value="" placeholder="用户名"/>

<scripttype="text/javascript">

varoTxt = document.getElementById("txt1");

oTxt.onfocus= function(){

oTxt.value = "";

}

oTxt.onblur= function(){

oTxt.value = "用户名";

}

</script>

</body>

</html>

0 0
原创粉丝点击