如何获取input输入框中的值
1个回答
展开全部
直接使用.value属性即可获取输入框的内容。
详细的步骤如下:
1、首先获取输入框对应的DOM元素,如:
1
var bt=document.getElementById("bt1")
2、将获取的到的DOM对象直接使用.value属性即可获取其中的输入内容,如:
1
document.write(bt.value);
3、完整实例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取<a href="https://www.baidu.com/s?wd=%E8%BE%93%E5%85%A5%E6%A1%86&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzuWIBryw9uWF-n1-hPyRd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErjDkrH0drjDknj6knWc1rjbz" target="_blank" class="baidu-highlight">输入框</a>的值</title>
<script type="text/javascript">
window.onload=function(){
var bt=document.getElementById("bt2");
var btt=document.getElementById("bt1");
bt.onclick=function(){
alert(bt1.value);
}
}
</script>
</head>
<body>
请输入内容<input type="text" id="bt1" />
<input type="button" id="bt2" value="获取<a href="https://www.baidu.com/s?wd=%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzuWIBryw9uWF-n1-hPyRd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErjDkrH0drjDknj6knWc1rjbz
详细的步骤如下:
1、首先获取输入框对应的DOM元素,如:
1
var bt=document.getElementById("bt1")
2、将获取的到的DOM对象直接使用.value属性即可获取其中的输入内容,如:
1
document.write(bt.value);
3、完整实例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取<a href="https://www.baidu.com/s?wd=%E8%BE%93%E5%85%A5%E6%A1%86&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzuWIBryw9uWF-n1-hPyRd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErjDkrH0drjDknj6knWc1rjbz" target="_blank" class="baidu-highlight">输入框</a>的值</title>
<script type="text/javascript">
window.onload=function(){
var bt=document.getElementById("bt2");
var btt=document.getElementById("bt1");
bt.onclick=function(){
alert(bt1.value);
}
}
</script>
</head>
<body>
请输入内容<input type="text" id="bt1" />
<input type="button" id="bt2" value="获取<a href="https://www.baidu.com/s?wd=%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzuWIBryw9uWF-n1-hPyRd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErjDkrH0drjDknj6knWc1rjbz
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询