html 获取文本框值,html - 如何在JavaScript中获取文本框值
html - 如何在JavaScript中获取文本框值
我正在尝试使用JavaScript从HTML文本框中获取值,但值不是在空格之后
例如:
我只得到:上面的“软件”。 我正在使用这样的脚本:
var jobValue = document.getElementById('txtJob').value
我如何获得全部价值:“软件工程师”?
15个解决方案
75 votes
您的元素没有ID,只有一个名称。 因此,您可以使用getElementsByName()方法获取具有此名称的所有元素的列表:
var jobValue = document.getElementsByName('txtJob')[0].value // first element in DOM (index 0) with name="txtJob"
或者您为元素分配ID:
Gumbo answered 2019-08-08T02:21:19Z
60 votes
+1 Gumbo:'id'是访问页面元素的最简单方法。 如果找不到具有给定ID的任何内容,IE(预版本8)将返回具有匹配“名称”的内容,但这是一个错误。
我只得到“软件”。
id-vs-name不会影响这个; 我怀疑发生了什么(与示例代码相反),你忘记引用你的'价值'属性:
bobince answered 2019-08-08T02:20:47Z
11 votes
var word = document.getElementById("word").value;//by id
or
var word = document.forms[0].elements[0].value;//by index
//word = a word from form input
var kodlandi = escape(word);//apply url encoding
alert(escape(word));
or
alert(kodlandi);
您没有使用表单输入值的编码问题所以不是浏览器添加到......
ontop在unicode编码/解码操作方面存在一些问题所以使用此函数编码字符串/数组
function urlencode( str )
{
// http://kevin.vanzonneveld.net3.
// + original by: Philip Peterson4.
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)5.
// * example 1: urlencode('Kevin van Zonneveld!');
// * returns 1: 'Kevin+van+Zonneveld%21'7.
var ret = str;
ret = ret.toString();
ret = encodeURIComponent(ret);
ret = ret.replace(/%20/g, '+');
return ret;
}
ex.
var word = "some word";
word = urlencode(word);
ferit answered 2019-08-08T02:21:51Z
7 votes
Enter your Name here:
function displayname() {
document.getElementById("demo").innerHTML =
document.getElementById("namehere").value;
}
zakara answered 2019-08-08T02:22:08Z
5 votes
将id的id属性设置为txtJob.当您致电getElementById时,您的浏览器会表现得很古怪。
Daniel A. White answered 2019-08-08T02:22:33Z
3 votes
如果它是一种形式,那么它将是:
然后你会在javascript中说:
var val= document.jojo.jobtitle.value
document.formname.elementname
Jim answered 2019-08-08T02:23:05Z
3 votes
当您需要文本框值时提供。 简单的一个:
var result = document.getElementById("textbox").value;
Vicky Chaudhary answered 2019-08-08T02:23:30Z
3 votes
如果您使用的是ASP.NET,则下面这些示例中的服务器端代码标记将提供确切的控件ID,即使您使用的是母版页。
使用Javascript:
document.getElementById("").value;
JQuery的:
$("#").val();
Sham answered 2019-08-08T02:23:59Z
0 votes
如果您使用任何用户控件并希望获取任何文本框值,则可以使用以下代码:
var result = document.getElementById('LE_OtherCostsDetails_txtHomeOwnerInsurance').value;
这里,LE_OtherCostsDetails是用户控件的名称,txtHomeOwnerInsurance是文本框的id。
Ranjan Srivastava answered 2019-08-08T02:24:32Z
0 votes
问题是你犯了一个小小的错误!
这是我使用的JS代码:
var jobName = document.getElementById("txtJob").value;
你不应该使用name =“”。 而是使用id =“”。
1010 answered 2019-08-08T02:25:12Z
0 votes
您需要更改以下代码: -
function myFunction(){
$a= document.getElementById("mainText").value;
alert($a);
}
Vishal Thakur answered 2019-08-08T02:25:37Z
0 votes
因为你在软件工程师html / php之间使用空间不会支持文本框下的值之间的空间,你必须使用这个代码它会工作
Vikas Sharma answered 2019-08-08T02:26:03Z
0 votes
var jobValue=document.FormName.txtJob.value;
尝试上面的代码。
jobValue:变量名。
FormName:html中表单的名称。
txtJob:文本框名称
Rahul answered 2019-08-08T02:26:49Z
0 votes
使用jquery应该很简单:
HTML:
JS:
var jobValue = $('#txtJob').val(); //Get the text field value
$('#txtJob').val(jobValue); //Set the text field value
JamesC answered 2019-08-08T02:27:19Z
0 votes
设置文本框的ID。即
在javascript中
var jobValue = document.getElementById('txtJob').value
在Jquery
var jobValue = $("#txtJob").val();
answered 2019-08-08T02:27:59Z
html 获取文本框值,html - 如何在JavaScript中获取文本框值相关推荐
- java+script+当前日期_如何在JavaScript中获取当前日期?
如何在JavaScript中获取当前日期? #1楼 您可以使用扩展了 Date对象的Date.js库,从而可以使用.today()方法. #2楼 如果您想对日期格式进行更多的粒度控制,我强烈建议您查看 ...
- 如何在JavaScript中获取时间戳
如何在JavaScript中获取时间戳 +运算符 我们可以使用+运算符将日期对象直接转换为UNIX时间戳. 例如,我们可以这样写: +new Date() +日期对象之前操作者触发valueOf的方法 ...
- 如何在 JavaScript 中获取当前日期?
问: 想要改进这篇文章?提供这个问题的详细答案,包括引文和解释为什么你的答案是正确的.没有足够细节的答案可能会被编辑或删除. 如何在 JavaScript 中获取当前日期? 答1: HuntsBot周 ...
- 如何在JavaScript中获取字符串数组的字符串?
本文翻译自:How do you get a string to a character array in JavaScript? How do you get a string to a chara ...
- css可以设置文本框颜色吗,如何在css中设置文本框颜色
如何在css中设置文本框颜色 发布时间:2021-04-29 15:33:54 来源:亿速云 阅读:72 作者:Leah 如何在css中设置文本框颜色?针对这个问题,这篇文章详细介绍了相对应的分析和解 ...
- 现在JavaScript日期–如何在JavaScript中获取当前日期
Many applications you build will have some sort of a date component, whether it's the creation date ...
- 如何在 JavaScript 中获取当前日期
日常开发中我们经常会用到某种日期功能,比如内容的创建日期.活动的时间戳等.处理日期和时间戳格式可能会很麻烦.在本文中,我们将一起学习如何在 JavaScript中以各种格式获取当前日期. JavaSc ...
- 文本挖掘和文本分析与nlp_如何在NLP中保护文本表示的隐私
文本挖掘和文本分析与nlp 问题概述 (Problem overview) Recently, we have been experiencing numerous breakthroughs in ...
- 文本上划线_如何在Word中对文本进行上划线
文本上划线 Underlining is a common task in Word, and easily done, but what if you need to overline (also ...
最新文章
- 楼主考南师计算机学硕,南京师范大学考研详解:据说这所学校不太好考?嗯,是真的!...
- linux设置开机自启动
- ORACLE_LOADER加载外部数据
- Android Makefile分析
- 移植开源QT软件-SameGame
- 提高Android Studio运行、编译速度方案
- ZMQ模式详解——发布/订阅模式
- ubuntu下Pure-FTPd的安装和配置
- 怎么源码安装 PKGCONFIGPATH设置转
- Web前端性能优化全攻略
- 软件测试之易用性测试
- 黑莓手机安装linux,Ubuntu下善用黑莓(备份,同步,装卸备份应用程序)
- 什么是集群农场渲染?一文带你快速了解
- CNCERT在FIRST会议关于国内PC被攻击的数据
- Chrome浏览器安装Adblock Plus插件拦截广告
- Cesium是什么,简介
- 3年自动化测试,我突然想转测试开发了,开发测试工具平台......
- 数据分析平台要点梳理
- 正则表达式同时匹配中英文_,还控制长度
- 数据结构-1.单链表的初始化