jQuery查找类并获取值 [英] jquery find class and get the value
本文介绍了jQuery查找类并获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取输入文本字段的值.
I am trying to get the value of an input text field.
HTML是:
<div id="start">
<p>
<input type="text" class="myClass" value="my value" name="mytext"/>
</p>
</div>
jquery是:
var myVar = $("#start").find('.myClass').val();
问题是myVar出现未定义状态.有人知道为什么吗?
The problem is that myVar is coming up undefined. Does anyone know why?
推荐答案
类选择器以点为前缀.您的.find()
丢失了,因此jQuery认为您正在寻找<myClass>
元素.
Class selectors are prefixed with a dot. Your .find()
is missing that so jQuery thinks you're looking for <myClass>
elements.
var myVar = $("#start").find('.myClass').val();
这篇关于jQuery查找类并获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文