web前端|js教程
js,表单,获取
web前端-js教程
第一种方法,通过元素的name获取
易语言源码没有模块,vscode 自增,ubuntu服务器怎么开机,tomcat 发布 静态,sqlite 表串位,N5分类插件,前端框架和库汇总,土里黄色爬虫有哪些,php成员变量,洛南优化seo,网站客服免费版,网页源代码有几种,网站模板首图,分销王免费版程序lzw
使用方法:
基于php的答题系统源码,ubuntu都是外国软件,查看tomcat相关进程,会爬虫技术,双城PHP培训,天企网络seo最新消息lzw
document.pref.color.value;//pref表示form表单的name,color是表单中元素的名称。
实例:
手机cpa源码,vue vscode前端,装了win10后找不到ubuntu了,tomcat线程原理,sqlite更新指定行,wp博客pjax插件,vue前端ui框架有哪些,github爬虫哪个最好用,iis配置 php环境,金堂优化seo,跑腿网站源码,网页游戏加速,免费制作相册视频网站模板免费下载lzw
Enter your favorite color:function showColor(){var color = document.pref.color.value;console.log("Your favorite color is: " + color); }Enter the name of your favorite car:
上面实例代码使用ocument.pref.color.value获取pref表单中name为color元素的值。
第二种方法:通过元素的index获取
使用方法:
document.pref.elements[0].value //表示name为pref表单中第一个元素的值
实例:
Enter your favorite color:function showCar(){var car = document.pref.elements[0].value;console.log("Your favorite car is: " + car); }Enter the name of your favorite car:
此实例获取了表单中第一个元素的值,表单的第一个元素应该是name为car的input
第三种方法:通过元素的id获取
document.getElementById("id").value;
实例:
function getName(){ var textName = document.getElementById("text_id").value; console.log("The textbox name is: " + textName); } This is a blank input textbox. Click on the button below to get the name of the textbox.
使用document.getElementById(“text_id”)获取id为text_id的input.
注:本文章的实例代码均可复制到这里运行并查看结果,你不妨试一把。