首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果选择列表为空,如何隐藏它

如果选择列表为空,如何隐藏它
EN

Stack Overflow用户
提问于 2013-11-19 20:58:47
回答 1查看 1.2K关注 0票数 0

下面的代码工作正常,但是如果没有选定的属性或者是空的,我想隐藏.search-form #city。提前谢谢你的时间。

代码语言:javascript
复制
$('.search-form #city').parent().hide()
cities = $('.search-form #city').html()
$('.search-form #country').change ->
  country = $('.search-form #country :selected').text()
  escaped_country = country.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
  options = $(cities).filter("optgroup[label='#{escaped_country}']").html()
  if options
    $('.search-form #city').html(options)
    $('.search-form #city').parent().show()
  else
    $('.search-form #city').empty()
    $('.search-form #city').parent().hide()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-19 21:45:17

代码语言:javascript
复制
    if($('.search-form #city').find('option').length==0 || $('.search-form #city').find(':selected').length==0)
 $('.search-form #city').hide();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20081895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档