如果没有附加,则隐藏本身
I want to hide "select" itself using jquery if there is no "option" append with it.
如果没有附加“选项”,我想使用jquery隐藏“select”本身。
6 个解决方案
#1
7
Assuming I've understood your question correctly, you can use the :empty
selector to find select
elements with no children:
假设我已正确理解你的问题,你可以使用:empty选择器来查找没有子元素的select元素:
$("select:empty").hide();
You may want to consider another answer if you have empty <optgroup>
element children within the select
(or any other non-option element children), as :empty
will consider the select
to not be empty (it has children, just no option
children).
如果你在select(或任何其他非选项元素子元素)中有空的
Also, as :empty
looks for elements with no child nodes (not just elements), text nodes are included (but note that comment nodes are ignored). That means it would only match select
elements like this:
另外,as:empty查找没有子节点(不仅仅是元素)的元素,包含文本节点(但请注意,忽略注释节点)。这意味着它只匹配像这样的选择元素:
<select></select> <!--Matches this-->
<select> </select> <!--Doesn't match this-->
更多相关文章
- jQuery.zTree 点击节点展开折叠子节点
- 具有嵌套元素的jQuery悬停事件
- Jquery隐藏()除一个类外所有具有特定类的元素
- jQuery -> 获取后代元素的三种方法
- JQuery操作<select>元素
- jQuery捕获被点击元素的ID
- Yii - 加载ajax表单元素的用户端验证
- 删除后重新插入后保留对元素的引用
- jquery中获取相邻元素相关的命令:next()、prev()和siblings()