问答详情
源自:6-3 鼠标经过事件(onmouseover)

为什么不能有条件地弹窗

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠标经过事件 </title>
<script type="text/javascript">
    function message(){
    passwd=document.getElementById("password").value;
    if(passwd=="")
      {confirm("请输入密码后,再单击确定!");} }
</script>
</head>
<body>
<form>
密码:<input name="password" type="password" id="password">
<input name="确定" type="button" value="确定" onmouseover="message()"/>
</form>
</body>
</html>

http://img.mukewang.com/5785ed450001a04705600344.jpg

我想让他先判断,如果输入框为空再弹窗,否则不弹窗,但是没有效果,执行上面的代码不弹窗。

提问者:CharlesLvm 2016-07-13 15:25

个回答

  • qq_囧rz_0
    2016-07-13 19:26:00

    <!DOCTYPE HTML>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title> 鼠标经过事件 </title>
        <script type="text/javascript">
            function message(){
                 var passwd = document.getElementById("password").value;
                console.log(passwd);
                if(passwd ===""){
                    confirm("请输入密码后,再单击确定!");
                }
            }
        </script>
    </head>
    <body>
    <form>
        密码:<input name="password" type="password" id="password">
        <input name="确定" type="button" value="确定" onclick="message()"/>
    </form>
    </body>
    </html>


  • qq_囧rz_0
    2016-07-13 19:06:58

    <!DOCTYPE HTML>
    <html>
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <title> 鼠标经过事件 </title>
       <script type="text/javascript">
           function message(){
                var passwd = document.getElementById("password").value;
               if(passwd ==""){
                   
               }else {
                   confirm("请输入密码后,再单击确定!");
               }
           }
       </script>
    </head>
    <body>
    <form>
       密码:<input name="password" type="password" id="password">
       <input name="确定" type="button" value="确定" onmouseover="message()"/>
    </form>
    </body>
    </html>

  • Jdude
    2016-07-13 17:07:05

    怕段语句的错误,null不是空值的意思,而是没有赋值。应改为“”即可。

  • CharlesLvm
    2016-07-13 16:49:28

    http://www.imooc.com/qadetail/134356

  • CharlesLvm
    2016-07-13 16:45:36

    你们说得都不对,我在别的章节中找到答案了,只需要把null换成“”就可以了。

  • 慕侠7342268
    2016-07-13 16:34:11

    passwd.value才是值,,你可以输出一下看一看,你获取到的是一个对象,不是值。。。

  • wajf
    2016-07-13 16:27:51

    在js中你并没有获取button按钮,