标签:
<span style="font-size:18px;">方法一、
<html>
<head>
<script language="javascript">
function print(){
var a=myform.name.value;
alert(a);
}
</script>
</head>
<body>
<form name="myform">
<input type="text" name="name" id="nn" />
<input type="button" name="button" value="获取" onclick="print()" />
</form>
</body>
</html>
这是获取网页input值的方法之一,给from一个名字然后在JavaScript的地方就可以用form的名字来调用form表单里input元素的value属性可以得到值,并把值赋给a,最后用JavaScript的alert()打印方法打印出来。
方法二、
Java代码 复制代码 收藏代码
<html>
<head>
<script language="javascript">
function print(){
var a=document.getElementById("id").value;
alert(a);
}
</script>
</head>
<body>
<form>
<input type="text" name="name" id="nn" />
<input type="button" name="button" value="获取" onclick="print()" />
</form>
</body>
</html></span><span style="font-size:18px;"> </span><pre name="code" class="javascript">方法N
$("#test").val()
$("input[name='test']").val()
$("input[type='text']").val()
$("input[type='text']").attr("value")版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/cwj1103/article/details/47102901