鼠标一点 文字消失 的有关问题

WBOY
Release: 2016-06-13 10:11:12
Original
1289 people have browsed it

鼠标一点 文字消失 的问题
请问大大们,如果鼠标一点文本框 文本框的默认值 就消失了,然后鼠标点别的地方,文本框又会自动显示默认值,这种效果该怎么做?
我上网搜了很多,用javascript写的,或者是onclick,onblur之类的我都试过,如果是纯html是可以用,但是写在php里面就一点作用都没有!这很奇怪啊!为什么?
代码如下:

JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><script language="JavaScript" type="text/javascript">   function addListener(element,e,fn){            if(element.addEventListener){                 element.addEventListener(e,fn,false);             } else {                 element.attachEvent("on" + e,fn);              }       }   var txt_oldPsw = document.getElementById("txt_oldPsw");   addListener(txt_oldPsw,"click",function(){txt_oldPsw.value = "";})   addListener(txt_oldPsw,"blur",function(){txt_oldPsw.value = "old Password";})   var txt_newPsw = document.getElementById("txt_newPsw");   addListener(txt_newPsw,"click",function(){txt_newPsw.value = "";})   addListener(txt_newPsw,"blur",function(){txt_newPsw.value = "new Password";})   var txt_reenter = document.getElementById("txt_reenter");   addListener(txt_reenter,"click",function(){txt_reenter.value = "";})   addListener(txt_reenter,"blur",function(){txt_reenter.value = "re-enter new password";})</script>
Copy after login


PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->echo "<tr><td><input class="txt_style" id="txt_oldPsw" style="font-size:10.5pt; color:#6b6b6b" type="text" name="txt_oldPsw" value="old password"></td></tr>";        echo "<tr><td><input class="txt_style" id="txt_newPsw" style="font-size:10.5pt; color:#6b6b6b" type="text" name="txt_newPsw" value="new password"></td></tr>";        echo "<tr><td><input class="txt_style" id="txt_reenter" style="font-size:10.5pt; color:#6b6b6b" type="text" name="txt_reenter" value="re-enter new password"></td></tr>";        echo "<tr><td><input class="btn_active" type="submit" name="$btn_active_define" value="$btn_active_text"></td></tr>";
Copy after login


谢谢了!

------解决方案--------------------
你的 js 要放在 php 之后!
即 txt_newPsw = document.getElementById("txt_newPsw");
需要在 ------解决方案--------------------
JS在清空文本框默认值的时候,顺带把type="text"改成type="password"不就得了。document.getElementById("inputId").type="password";
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!