首页 新闻 赞助 找找看

关于onclick的问题

0
[已解决问题] 解决于 2016-05-11 12:25
 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 8 <title>用户界面</title>
 9 <style type="text/css">
10 table.tab{
11     font-family: verdana,arial,sans-serif;
12     font-size:11px;
13     border-color: red;
14     border-color: #666666;
15     border-collapse: collapse;
16 }
17 table.tab tr{
18     border:30px;
19     border-color: #666666;
20     padding: 8px;
21     border-style: solid;
22 }
23 table.tab td{
24     border-color: #666666;
25     background-color: #ffffff;
26 }
27 #btn{
28     background-color: #666666;
29 }
30 </style>
31 <script type="text/javascript">
32 function clcktd(){
33     var a=document.getElementsByName("newpassword");
34     var b=document.getElementsByName("conpassword");
35     if((au.password=null || a==null || b==null) && (au.password=null && a==null && b==null))
36         alert("密码不能为空!");
37     if(b!=a){
38         document.getElementById("inputpsd");
39         ctrl.focus(); 
40     }    
41 }
42 </script>
43 </head>
44 <body>
45     <form action="" method="post">
46         <div align="center">
47             <table class="tab">
48                 <tr>
49                     <td colspan="2" align="center"><h2>
50                         <%=session.getAttribute("uname") %>
51                         </h2>
52                     </td>
53                 </tr>
54                 <tr>
55                     <td>
56                         旧密码:
57                     </td>
58                     <td>
59                         <input name="au.password" type="password" />
60                     </td>
61                 </tr>
62                 <tr>
63                     <td>
64                         新密码:
65                     </td>
66                     <td>
67                         <input name="newpassword" type="password"/>    
68                     </td>
69                 </tr>
70                 <tr>
71                     <td>
72                         确认密码:
73                     </td>
74                     <td>
75                         <input name="conpassword" type="password" id="inputpsd"/>    
76                     </td>
77                 </tr>
78                 <tr>
79                     <td align="right" colspan="2" id="btn">
80                         <button type="submit" onclick="clcktd()">保存</button>    
81                     </td>
82                 </tr>
83             </table>
84         </div>
85     </form>
86 </body>
87 </html>

按理说有alter呀,但是它根本就不会弹窗,是我的条件写错了?前端来帮忙撒

cocoyoona的主页 cocoyoona | 初学一级 | 园豆:20
提问于:2016-05-11 10:55
< >
分享
最佳答案
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>用户界面</title>
    <style type="text/css">
        table.tab{
            font-family: verdana,arial,sans-serif;
            font-size:11px;
            border-color: red;
            border-color: #666666;
            border-collapse: collapse;
        }
        table.tab tr{
            border:30px;
            border-color: #666666;
            padding: 8px;
            border-style: solid;
        }
        table.tab td{
            border-color: #666666;
            background-color: #ffffff;
        }
        #btn{
            background-color: #666666;
        }
    </style>
    <script type="text/javascript">
        function clcktd(){
            var a=document.getElementsByName("newpassword");
            var b=document.getElementsByName("conpassword");
            var c=document.getElementsByName("aupassword");
            if(a[0].value == '' || b[0].value == '' || c[0].value == '') {
                alert("密码不能为空!");
                return false;
            }
            if(a[0].value != b[0].value){
                var ctrl = document.getElementById("inputpsd");
                ctrl.focus();
                return false;
            }    
        }
    </script>
</head>
<body>
    <form action="" method="post" onsubmit="return clcktd()">
        <div align="center">
            <table class="tab">
                <tr>
                    <td colspan="2" align="center"><h2>
                        <%=session.getAttribute("uname") %>
                    </h2>
                </td>
            </tr>
            <tr>
                <td>
                    旧密码:
                </td>
                <td>
                    <input name="aupassword" type="password" />
                </td>                 </tr>
                <tr>
                    <td>
                        新密码:
                    </td>
                    <td>
                        <input name="newpassword" type="password"/>    
                    </td>
                </tr>
                <tr>
                    <td>
                        确认密码:
                    </td>
                    <td>
                        <input name="conpassword" type="password" id="inputpsd"/>    
                    </td>
                </tr>
                <tr>
                    <td align="right" colspan="2" id="btn">
                        <button type="submit">保存</button>    
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

唉..幫你寫完了

奖励园豆:5
RosonJ | 老鸟四级 |园豆:4910 | 2016-05-11 11:28

蟹蟹你

cocoyoona | 园豆:20 (初学一级) | 2016-05-11 12:10
其他回答(9)
0

if((au.password

 不知道你用的什么浏览器,

想前台开发,你得把,脚本错误,脚本调试这几个选项打开吧。

怎么打开,你去Bing  google. 都行,基本上都是 高级-设置-选项 高级选项。里面都有。

二十二号同学 | 园豆:790 (小虾三级) | 2016-05-11 10:56

这个怎么了?(() &&())

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 10:58

@眉间剪水泛千愁: au.password 未定义?

支持(0) 反对(0) 二十二号同学 | 园豆:790 (小虾三级) | 2016-05-11 10:59

@二十二号同学: 有的,在那边

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:00

@眉间剪水泛千愁: F12 还有你这个页面好像也没有引用别的Script 吧

如果你用IE , 打开状态栏,看看你的 左下角是否有 叹号。

支持(0) 反对(0) 二十二号同学 | 园豆:790 (小虾三级) | 2016-05-11 11:02

@二十二号同学: 系谷歌浏览..都是英文

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:04
0

debugger;

调试一下。

绯村剑心丶 | 园豆:137 (初学一级) | 2016-05-11 10:59

不会= =

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:01

@眉间剪水泛千愁: 学会调试很重要,以一个实习一年的新手身份向你建议。(ง •̀_•́)ง

支持(0) 反对(0) 绯村剑心丶 | 园豆:137 (初学一级) | 2016-05-11 11:04

@橘色大耳朵猫: 那怎么调试..JavaScript我没调试过

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:04

@眉间剪水泛千愁: 在你的JS语句上面写debuger; 

IE浏览器的话F12 点脚本 然后 点启动调试 就可以一步一步看啦。

支持(0) 反对(0) 绯村剑心丶 | 园豆:137 (初学一级) | 2016-05-11 11:06

@眉间剪水泛千愁: debugger;

前面少了个g

支持(0) 反对(0) 绯村剑心丶 | 园豆:137 (初学一级) | 2016-05-11 11:08

@橘色大耳朵猫: 噗..谷歌浏览器,F12debug,但是全是英文看不懂

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:08

@眉间剪水泛千愁: 哪只好请求 百度翻译 啦~我英文也很差。电脑应该自带IE吧  用IE试试

支持(0) 反对(0) 绯村剑心丶 | 园豆:137 (初学一级) | 2016-05-11 11:11
0

 

function clcktd(){
     var a=document.getElementsByName("newpassword");
     var b=document.getElementsByName("conpassword");
     if(a.value==""|| b .value=="")
         alert("密码不能为空!");
     if(b.value!=a.value){
         document.getElementsById("inputpsd").focus();
     }    
 }

 

 

无影飞絮剑 | 园豆:1155 (小虾三级) | 2016-05-11 11:12

这个样子就好了?

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:12

不能==null判断么?

 

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:13

@眉间剪水泛千愁:你试试再说话吧

支持(0) 反对(0) 无影飞絮剑 | 园豆:1155 (小虾三级) | 2016-05-11 11:14

@无影飞絮剑: 木有反应

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:16
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
table.tab{
     font-family: verdana,arial,sans-serif;
     font-size:11px;
    border-color: red;
     border-color: #666666;
     border-collapse: collapse;
 }
 table.tab tr{
     border:30px;
     border-color: #666666;
     padding: 8px;
     border-style: solid;
 }
 table.tab td{
     border-color: #666666;
     background-color: #ffffff;
 }
 #btn{
 background-color: #666666;

 }
 </style>
  <script type="text/javascript">
 function clcktd(){
     var old_password=document.getElementById("oldpassword").value;
     var new_password=document.getElementById("newpassword").value;
     var con_password=document.getElementById("inputpsd").value;
     //建议上面的写法用jquery来获取
     if(old_password==null||new_password==null||con_password==null||old_password==""||new_password==""||con_password=="")
     {
         alert("密码不能为空!");
     }
     if(b!=a){
         document.getElementById("inputpsd");
         ctrl.focus(); 
     }    
 }
</script>
 </head>
 <body>
     <form action="" method="post">
         <div align="center">
             <table class="tab">
                 <tr>
                     <td colspan="2" align="center"><h2>
                         <%=session.getAttribute("uname") %>
                         </h2>
                     </td>
                 </tr>
                 <tr>
                     <td>
                         旧密码:
                     </td>
                     <td>
                         <input type="password" name="oldpassword" id="oldpassword" />
                     </td>
                 </tr>
                 <tr>
                    <td>
                         新密码:
                     </td>
                     <td>
                        <input name="newpassword" id="newpassword" type="password" />    
                     </td>
                 </tr>
                 <tr>
                     <td>
                         确认密码:
                     </td>
                     <td>
                         <input name="conpassword" type="password" id="inputpsd"/>    
                     </td>
                 </tr>
                 <tr>
                     <td align="right" colspan="2" id="btn">
                         <button type="submit" onclick="clcktd()">保存</button>   
                     </td>
                 </tr>
             </table>
         </div>
     </form>
 </body>
 </html>
View Code

这个可以

心怀宇宙 | 园豆:643 (小虾三级) | 2016-05-11 11:17

到我这里就不行了- -..委屈

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 11:23

@眉间剪水泛千愁: 你把我script和body之间的东西都复制过去,再不行你就用jquery来获取,就是我注视的上面那三个。

支持(0) 反对(0) 心怀宇宙 | 园豆:643 (小虾三级) | 2016-05-11 11:26

@双子rain: copy过来可以用- -

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 12:14

@眉间剪水泛千愁: 仔细检查你哪里写的不对,写完认真看一下,发现你不够细心。

支持(0) 反对(0) 心怀宇宙 | 园豆:643 (小虾三级) | 2016-05-11 12:15

@双子rain: 只能选一个答案..宝宝对不起你

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 12:26

@眉间剪水泛千愁: 没关系,多细心点,写完多检查。

支持(0) 反对(0) 心怀宇宙 | 园豆:643 (小虾三级) | 2016-05-11 13:24

@双子rain: 嗯嗯嗯

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 13:25
0

au.password=null这写错了吧!少了个=号

sky_keke | 园豆:181 (初学一级) | 2016-05-11 11:31
0

这个太有趣了我也要来。。。

JaneEyre | 园豆:454 (菜鸟二级) | 2016-05-11 11:37
0

上面的你们需要买飞机票过去亲自指导

回看欧洲 | 园豆:208 (菜鸟二级) | 2016-05-11 11:46
0

2园豆到手~

小光 | 园豆:1766 (小虾三级) | 2016-05-11 11:46
0

2园豆到手~

✎﹏ℳ๓₯㎕ღ | 园豆:1499 (小虾三级) | 2016-05-11 12:26

呀呀呀呀到我这里偷豆豆

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 12:27

@眉间剪水泛千愁: 是从系统里扣的, 不是从你那里扣的

支持(0) 反对(0) 二十二号同学 | 园豆:790 (小虾三级) | 2016-05-11 13:18

@二十二号同学: 你也来了

支持(0) 反对(0) cocoyoona | 园豆:20 (初学一级) | 2016-05-11 13:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册