本文摘自PHP中文网,作者青灯夜游,侵删。
javascript可以获取input的值,方法:首先使用“document.getElementById("id值")”语句获取到input元素对象;然后使用“input元素对象.value”语句来获取input元素的值即可。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
javascript可以获取input值
代码示例:
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" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< title >JavaScript中获取input元素value值</ title >
< link rel = "stylesheet" href = "" >
< script >
function printInputValue() {
var inputValue = document.getElementById("demo1").value;
console.log(inputValue);
document.getElementById("demo2").innerHTML = inputValue;
}
</ script >
</ head >
< body >
< input type = "text" id = "demo1" >
< button onclick = "printInputValue()" >获取input元素value值</ button >
< p id = "demo2" ></ p >
</ body >
</ html >
|
运行结果:
说明:
getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用。
value 属性可设置或返回文本域的值。
【推荐学习:javascript高级教程】
以上就是javascript可以获取input的值吗的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
c和javascript区别有哪些
javascript proxy()对象的理解使用(代码示例)
javascript求x平方怎么做
javascript区分大小写吗
javascript的三大组成部分
html里table表数据如何转为json格式
javascript中如何对dom元素的添加
javascript能做什么?
荟萃javascript箭头函数语法小结
快速入门createjs实例教程
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » javascript可以获取input的值吗