问答详情
源自: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(){

        var txt=document.getElementById("num").innerHTML;

        

        if(!txt){

      confirm("请输入密码后,再单击确定!");}

      }

</script>

</head>

<body>

<form>

密码:<input name="password" id="num" type="password" >

<input name="确定" type="button" value="确定" onmouseover="message()"/>

</form>

</body>

</html>


提问者:精慕门9295324 2018-09-22 11:06

个回答

  • 慕移动9181930
    2022-03-29 04:05:50

    养成转义好习惯,或者加r#39;xxx#39;

    tmyxicxzmbbdgkvzfukdbaogllobiftyfdexofxsahfmmqlnzbszlragczwhoqzojrlwdajhafrpzloiuxwvsxyyonlncdtwkuyodbmzyzvpdttiasoexkmhemlafhowpyocmdpbowjudooqa

  • 夙和
    2018-09-29 11:07:59

    <!DOCTYPE html>

    <html>

    <head>

        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

        <title>判断输入框是否为空</title>

        <script>

    function message(){

    var x=document.getElementById("num").value;

    var y=document.getElementById("tip");

    if(!x){

    y.innerHTML="请输入密码后,再单击确定!";

    }

    else{

    y.innerHTML="提交成功!";

    }

    }

    </script>

    </head>


    <body>

      请输入密码:<input type="password" name="password" id="num"><br> 

      <div id="tip"></div>

      <input type="button" value="确定" id="btn" onMouseOver="message()">

    </body>

    </html>


    ps:

    document.getElementById("num").value;   指的是获取文本框的内容;

    document.getElementById("num").innerHTML;  指的是获取文本的内容;

  • qq_水帝_03659279
    2018-09-22 16:40:32

       应该是var txt=document.getElementById("num").value;

    判断的值有问题