如何在JavaScript中获得文本框的值 [英] How to get text box value in JavaScript

查看:101
本文介绍了如何在JavaScript中获得文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用JavaScript从HTML文本框中获取值,但值不会在空格之后出现

例如:

 < input type =textname =txtJobvalue =software engineer> 

我只从上面得到:software。我使用这样的脚本:
$ b

  var jobValue = document.getElementById('txtJob')。value 

如何获得完整值:software engineer?

解决方案

+1 Gumbo:'id'是访问页面元素的最简单方法。 IE浏览器(pre version 8)如果找不到具有给定ID的任何内容,就会返回匹配name的东西,但这是一个bug。



id-vs-name不会影响这个;我怀疑发生了什么事(与示例代码相反),您已经忘记引用您的值属性:

 < ; input type =textname =txtJobvalue = software engineer> 


I am trying to use JavaScript to get the value from an HTML text box but value is not coming after white space

For example:

<input type="text" name="txtJob" value="software engineer">

I only get: "software" from the above. I am using a script like this:

var jobValue = document.getElementById('txtJob').value

How do I get the full value: "software engineer"?

解决方案

+1 Gumbo: ‘id’ is the easiest way to access page elements. IE (pre version 8) will return things with a matching ‘name’ if it can't find anything with the given ID, but this is a bug.

i am getting only "software".

id-vs-name won't affect this; I suspect what's happened is that (contrary to the example code) you've forgotten to quote your ‘value’ attribute:

<input type="text" name="txtJob" value=software engineer>

这篇关于如何在JavaScript中获得文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆