![](/img/trans.png)
[英]why can't I do a loop with `var output = document.getElementById('message').innerHTML;`
[英]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.