以下代码工作正常但我想隐藏.search-form #city
如果它没有选择属性或者它是空的。提前感谢您的时间。
$('.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()
答案 0 :(得分:2)
if($('.search-form #city').find('option').length==0 || $('.search-form #city').find(':selected').length==0)
$('.search-form #city').hide();