如何使用jQuery获取文本框的值? [英] How do I get the value of a textbox using jQuery?

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

问题描述

我可以得到像这样的元素$("#txtEmail"),但是我不确定如何获取实际值.

I can get the element like this $("#txtEmail") but I'm not sure how to get the actual value.

推荐答案

有一个.val()方法:

如果输入的ID为txtEmail,则可以使用以下代码访问文本框的值:

If you've got an input with an id of txtEmail you can use the following code to access the value of the text box:

$("#txtEmail").val()

您还可以使用val(string)方法设置该值:

You can also use the val(string) method to set that value:

$("#txtEmail").val("something")

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

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