<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="div1">
<input class="key" type="text" onfocus="func1()" onblur="func2()" value="請輸入內容">
</div>
<script>
function func1() { var divs=document.getElementsByClassName("div1")[0]; var ini=divs.getElementsByClassName("key")[0]; if (ini.value=="請輸入內容"){ ini.value=""; } } function func2() { var divs=document.getElementsByClassName("div1")[0]; var ini=divs.getElementsByClassName("key")[0]; if (ini.value.trim().length==0){ ini.value="請輸入內容"; } } </script>
</body>
</html>