请问大大们,如果鼠标一点文本框 文本框的默认值 就消失了,然后鼠标点别的地方,文本框又会自动显示默认值,这种效果该怎么做?
我上网搜了很多,用javascript写的,或者是onclick,onblur之类的我都试过,如果是纯html是可以用,但是写在php里面就一点作用都没有!这很奇怪啊!为什么?
代码如下:<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>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' $psw_disable></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' $psw_disable></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' $psw_disable></td></tr>";
echo "<tr><td><input class='btn_active' type='submit' name='$btn_active_define' value='$btn_active_text'></td></tr>";
谢谢了!
我上网搜了很多,用javascript写的,或者是onclick,onblur之类的我都试过,如果是纯html是可以用,但是写在php里面就一点作用都没有!这很奇怪啊!为什么?
代码如下:<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>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' $psw_disable></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' $psw_disable></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' $psw_disable></td></tr>";
echo "<tr><td><input class='btn_active' type='submit' name='$btn_active_define' value='$btn_active_text'></td></tr>";
谢谢了!
解决方案 »
- 获得的数据值传不过来
- 为什么有人写程序一页内有很多<?php ?> <?php ?>
- 如何使程序每查询到一条结果即显示在网页上?
- 80分提问: 用session_set_save_handler设置过的write函数中不能调用外部对象,怎么回事?
- php点击新闻标题怎么显示详细新闻?
- 如何用PHP获得来访者的MAC地址?
- php编写的软件如何实现用注册码机制来保护软件被非法复制或盗版?
- 我想使用smarttemplate模板制作网站,对模板语法我已经了解了,可是我不知道从何入手
- 求PHP入门的几个东西...
- HTML2pdf将html转为pdf html里面图片丢失
- cookie
- 为什么我通过浏览器能正常访问我的PHP文件,能看到这个PHP文件解析后的正常输出。但是我用PHP CLI
<?php
//PHP代码
if(...){
?>
HTML/js
<?php
}
?>
用echo输出大量的HTML是吃力不讨好的事情。
即 txt_newPsw = document.getElementById("txt_newPsw");
需要在 <input class='txt_style' id='txt_newPsw' style='font-size:10.5 ...
加载完成之后执行
多谢!您说的很对!在结贴之前顺便再问一个问题。
我想做个文本框,输入密码用的。
比如在鼠标没点之前,文本框里默认显示“请输入密码”,然后鼠标点上去之后,默认文字消失,输入完密码,显示为星号,即使鼠标点别的地方,星号密码也不会消失,这该怎么做?
如果把type=password的话,那默认值也会变成星号的谢谢!