在JS文件中如何得到html文件中输入框的值

如题所述

把输入框放到一个form表单里
<form name="frm">
<input type="text" name=“name” id=“id_name”..../>
</form>
这样在js里就可以document.frm.name.value就是输入框的值
或者document.getElementById("id_name").value也是可以的
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-10-13
document.getElementById("id_name").value
或者
docuemt.getElementById("id_name").innerHTML

如:
<html>
<head>
<title> New Document </title>
</head>
<script type="text/javascript">
function getValue()
{
var v = document.getElementById("username");
alert(v.value);
}
</script>
<body>
<form>
username:<input type="text" id="username"/>
<input type="submit" value="submit" onclick="getValue()"/>
</form>
</body>
</html>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网