如果标签< ul>之间为空,发出警报. [英] if empty between tag <ul> give alert.?

查看:60
本文介绍了如果标签< ul>之间为空,发出警报.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要标签ul警报hello之间是否为空.怎么样?

I want if empty between tag ul alert hello. how is it?

<button class="click">Click</button><p>

<span>
    <ul></ul>
</span>

js:

$('.click').click(function() {
    if('span ul' == ''){alert('hello')};
});

示例:: http://jsfiddle.net/KDAwP/1/

推荐答案

使用jQuery :empty选择器尝试此操作,该选择器选择空元素.空元素是没有子元素或文本的元素.

Try this using jQuery :empty selector which selects empty elements. An empty element is an element without child elements or text.

$('.click').click(function() {
    if($('ul:empty').length){alert('hello')};
});

jQuery在span标记内找不到ul.实际上,您不应该在span标记内包含ul.

jQuery is not finding ul inside a span tag. Actually you should not have ul inside a span tag.

尝试这个小提琴就可以了.

Try this fiddle it works perfectly fine.

http://jsfiddle.net/KDAwP/6/

这篇关于如果标签&lt; ul&gt;之间为空,发出警报.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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