<input type="text" name="form" id="form" /> 获取id=“” 引号里的值,也就是form js如何获得这个值呢?
直接用 document.getElementById('form').value
如下面的完整演示代码(保存为htm即可查看):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>完整演示</title>
</head>
<body>
<input type="text" name="form" id="form" />
<input onclick="alert(document.getElementById('form').value);" type="button" name="submit" value="测试" />
</body>
</html>
-------------------------------------------
注意那个input的id名称要和document.getElementById('form')这里面的id名称一致就行了
如下面的完整演示代码(保存为htm即可查看):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>完整演示</title>
</head>
<body>
<input type="text" name="form" id="form" />
<input onclick="alert(document.getElementById('form').value);" type="button" name="submit" value="测试" />
</body>
</html>
-------------------------------------------
注意那个input的id名称要和document.getElementById('form')这里面的id名称一致就行了
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-09-16
$("input").attr("id");追问
如果有多个input 呢?
追答你可以给input添加一个class , 然后$(".你设置的class").attr("id"); 。 如果你的input放在某个元素中的话就更好取了
本回答被提问者采纳