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(或任何其他非选项元素子元素)中有空的元素子元素,你可能想要考虑另一个答案,如:empty会认为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-->

更多相关文章

  1. jQuery.zTree 点击节点展开折叠子节点
  2. 具有嵌套元素的jQuery悬停事件
  3. Jquery隐藏()除一个类外所有具有特定类的元素
  4. jQuery -> 获取后代元素的三种方法
  5. JQuery操作<select>元素
  6. jQuery捕获被点击元素的ID
  7. Yii - 加载ajax表单元素的用户端验证
  8. 删除后重新插入后保留对元素的引用
  9. jquery中获取相邻元素相关的命令:next()、prev()和siblings()

随机推荐

  1. Android 在程序界面上显示图片
  2. android configChanges
  3. android定位功能(二)
  4. Android工具库
  5. Android 6.0 Ethernet流程分析记录
  6. 如何让Android横竖屏切换时不销毁当前act
  7. Android中一些比较好的开源代码项目
  8. Android(安卓)Service的启动流程源码分析
  9. 【Android】安卓中常用的图片加载方法
  10. android monkeyrunner 1