检查下拉列表中是否有值
我有清单:
<td id="filter_analyst">
<select>
<option>mike1</option>
<option>mike2</option>
<option>mike3</option>
</select>
我正在尝试检查是否存在某些值:
var name = 'mike1';
alert(name);
var t = ($("#filter_analyst").find("[value='"+name+"']").length) > 1;
alert(t);
但是变得错误......
我做错了什么吗? http://jsfiddle.net/BFMD4/32/
提前致谢!
I have the list:
<td id="filter_analyst">
<select>
<option>mike1</option>
<option>mike2</option>
<option>mike3</option>
</select>
and i'm trying to check if some value exist:
var name = 'mike1';
alert(name);
var t = ($("#filter_analyst").find("[value='"+name+"']").length) > 1;
alert(t);
But getting false...
Am I doing something wrong?
http://jsfiddle.net/BFMD4/32/
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
value
不是选项的标签,而是中的 HTML 标记。
请参阅此工作示例: http://jsfiddle.net/ZZaSW/
[编辑] 另一个示例更像您的 HTML (但是没有表格的
不起作用,因此我在示例中放置了
)。
这是 HTML:
和 js:
The
value
is not the label of the option but the HTML tag within the<option>
.See this working example: http://jsfiddle.net/ZZaSW/
[EDIT] Another example more like your HTML (but a
<td>
without a table doesn't work so I've put a<div>
for the example).Here is the HTML:
And the js:
http://jsfiddle.net/BFMD4/37/
在您的原始示例中,td 选择器无法正常工作,因为它缺少包装表和 tr 标签。
http://jsfiddle.net/BFMD4/37/
In your original example, the td selector was not working because it was missing the wrapping table and tr tags.
工作答案
http://jsfiddle.net/BFMD4/45/
working answer
http://jsfiddle.net/BFMD4/45/
尝试演示
Try demo
试试这个
HTML 如下
JS 代码如下,
Try This
HTML as below
JS Code as Below,