如何检查JQuery select中是否已经存在选项 [英] How can I check whether a option already exist in select by JQuery

查看:69
本文介绍了如何检查JQuery select中是否已经存在选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查JQuery的select中是否已经存在选项?

How can I check whether a option already exist in select by JQuery?

我想动态地将选项添加到select中,因此我需要检查该选项是否已经存在以防止重复.

I want to dynamically add options into select and so I need to check whether the option is already exist to prevent duplication.

推荐答案

如果已存在,则结果为true:

This evaluates to true if it already exists:

$("#yourSelect option[value='yourValue']").length > 0;

这篇关于如何检查JQuery select中是否已经存在选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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