检索Jquery中输入文本字段的值 [英] Retrieving the Value of an input text field in Jquery

查看:72
本文介绍了检索Jquery中输入文本字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绝对菜鸟问题.

我有一个表格

<form>
  <input type="text" id="cars" name="cars"/>
</form>

当用户单击链接时,我的jquery函数需要获取此输入字段的当前值.

When the user clicks on a link , my jquery function needs to pick up the current value of this input field.

如何检索此值?进行$(#cars").val给我一个html块,而不是用户键入的字符串,而且$("cars").text也抛出一个空值.

How do I retrieve this value? Doing a $("#cars").val gives me a block of html and not the string typed in by the user, Also $("cars").text throws a null value.

有什么建议吗?

推荐答案

确保您将其作为函数调用(带括号!),$("#cars").val()将在此处为您提供所需的信息.

Make sure you're calling it as a function (with parenthesis!), $("#cars").val() will give you want you want here.

例如:

$("button").click(function() {
    alert($("#cars").val());
});​

您可以在此处进行测试,而没有括号,您将获得函数,而不执行它,并获得结果了解我在演示.

You can test it out here, without the parenthesis you're getting the function, not executing it and getting the result, see what I mean in a demo of that here.

这篇关于检索Jquery中输入文本字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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