繁体   English   中英

var x=document.getElementById(“mytext”).value;为什么我将值更改为innerHTMl 或innerText,它不起作用?

[英]var x=document.getElementById(“mytext”).value;Why i change the value to innerHTMl or innerText,it do not work?

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>

    <body>
        <input type="text" id="mytext">
        <input type="button" onclick="myfuction()" value="click">

        <script type="text/javascript">
         //the problem is here,why the value is ok?but innerText don't
            function myfuction() {
                var a = document.getElementById("[mytext][1]").value;
                alert(a);
            }
        </script>
      </body>
    </html>

图片

我想在输入框中输入文字,点击按钮会提示我。

getElementById作用于元素的ID属性。

 function myfuction() { var a = document.getElementById("mytext").value; alert(a); }
 <input type="text" id="mytext"> <input type="button" onclick="myfuction()" value="click">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM