js 怎么获取到input输入的值

如题所述


<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="https://cdn.bootcss.com/jquery/1.8.0/jquery.js "></script>
</head>
<body>
<input id="myText" type="text"/>
<button onclick="getVal()">获取值</button>
<script type="text/javascript">
function getVal(){
var myVal= document.getElementById("myText").value;
alert('文本框的值为:'+myVal);
}

</script>
</body>
</html>

温馨提示:答案为网友推荐,仅供参考
相似回答