为什么我得不到input的value值?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单验证</title>
    <style>
        .title{
            font-weight: bold;
            font-size:18px;
        }
        .names{
            width:358px;
            height:42px;
            margin-left:38px;

            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        .btn{
            width:78px;
            height:42px;
            margin-left:15px;

            background: rgb(46,122,184);
            color: #fff;

            font-size:18px;
            font-weight: bold;

            outline: none;
            border:0;
            border-radius: 5px;
        }

        .prompt{
            margin-left:78px;

            font-size:16px;
            color: #ccc;
        }


    </style>
</head>
<body>
    <form action="#">
        <p>
            <label for="names" class="title">名称</label>
            <input type="text" class="names" id="names" name="user_name">
            <button type="submit" class="btn">验证</button>
        </p>
        <p class="prompt">必填,长度为4~16个字符</p>
    </form>
</body>
<script>
    var names=document.getElementById("names");
    


</script>
</html>


19990000
浏览 1724回答 4
4回答

Samaritan

var names = document.getElementById("names"); var namesValue = names.value;

萌萌乐

names.value

慕粉2348563550

var names=document.getElementById("names").value;

骑驴的帅小伙

ById只是获取元素,获取value要 names.value
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript