首页 新闻 赞助 找找看

关于js一些问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-08-08 11:44
 1 <script type="text/javascript">
2 window.onload =function () {
3 var UserPwd = document.getElementById("UserPwd");
4 var userpwd = document.getElementById("userpwd");
5 //获得焦点后触发的事件
6 UserPwd.onfocus =function () {
7 if (this.value !="请输入密码") return;
8 this.style.display ="none";
9 userpwd.style.display ="";
10 userpwd.value ="";
11 userpwd.focus();
12 };
13 //失去焦点后触发的事件
14 userpwd.onblur =function () {
15 if (this.value !="") return;
16 this.style.display ="none";
17 UserPwd.style.display ="";
18 UserPwd.value ="请输入密码";
19 }
20 }
21 </script>
22 </head>
23 <body>
24 <div style="width:255px">
25 <input type="text" class="UserEmail"/><div class="emailerror">邮箱已存在!</div><br />
26 <input type="text" class="UserPwd" id="UserPwd" value="请输入密码"/>
27 <input type="password" class="userpwd" id="userpwd" style="display:none"/>

为什么这段代码中的js代码不起作用呢?求解

阿磊ing的主页 阿磊ing | 初学一级 | 园豆:2
提问于:2012-04-10 07:47
< >
分享
所有回答(5)
0

我测试了一下,FireFox跟Chrome及IE89是好的,IE7下有问题,是在获得焦点事件后,IE7也触发了失去焦点事件导致的,IE6没测,呆会儿找到解决方案后再补充

artwl | 园豆:16736 (专家六级) | 2012-04-10 08:13
0

你要做什么呢?可否说明一下你这段js的意图

玉开 | 园豆:8822 (大侠五级) | 2012-04-10 08:55

我想做一个注册的界面

支持(0) 反对(0) 阿磊ing | 园豆:2 (初学一级) | 2012-04-10 11:55
0

你用jquery去验证可能会更好一些。。。而且不会有浏览器不兼容的问题。。。

KivenRo | 园豆:1734 (小虾三级) | 2012-04-10 09:07
0

先引入js

    $(function(){
  //获得焦点后触发的事件
      $("#UserPwd").focus(function(){
     if (this.value !="请输入密码") return;
      this.style.display ="none";
      userpwd.style.display ="";             
    userpwd.value ="";
    userpwd.focus();
   });       
         //失去焦点后触发的事件  
    $("#UserPwd").blur(function(){
   if (this.value !="") return;
      this.style.display ="none";
      UserPwd.style.display ="";                    
        UserPwd.value ="请输入密码";
   });       
   
         
 });

wlz0815 | 园豆:587 (小虾三级) | 2012-04-10 09:22
0

debug下才能知道问题在哪

OOLi | 园豆:163 (初学一级) | 2012-04-10 17:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册