我有以下div
与以下children
。元素没有可见内容
<div>
<img src="http://zferral.com">
<!--zferral is an invisible image analytics tool-->
<script>Some Comment</script>
</div>
这个div有三件事。 A script
,image
和comment
。
我需要知道它们是否真的在div内并返回一个布尔值。
我需要这个可用于jQuery,所以我可以隐藏div如果他们是不可见的孩子。
这些应该都返回true
(底部)。顶部示例应返回false
。
<div>
<img src="http://zferral.com">
<!--zferral is an invisible image analytics tool-->
<script>Some Comment</script>
<p>Hello</p>
</div>
<div>
<img src="http://zferral.com">
<!--zferral is an invisible image analytics tool-->
<script>Some Comment</script>
Hello
</div>
<div>
<img src="http://zferral.com">
<!--zferral is an invisible image analytics tool-->
<script>Some Comment</script>
<img src="anything other than zferral">
</div>
我的进度
我用.clone()
复制DIV找到所有的脚本标记删除它们。
我需要使用正则表达式来解析和删除所有评论。
然后使用正则表达式和.find在链接中使用zferral获取图像。
最后,我应该有一个字符串<div></div>
,并可以确认它是空的。
我处于停滞状态,我不完全知道这是否是最好的方法。
part.additional = function(){
var test = $('.group[style="border: none;"]').clone().find('script').remove().end();
((jQuery('#content .group').length > 1 && jQuery('#content .group:nth-child(2)').find('*:visible').length !== 0)) ? jQuery('#content').clone(true).attr('id','additional').find('.group:first').remove().end().find('script').remove().end() : false ;
}
var a = jQuery('#content .group').length > 1;
var b = jQuery('#content').clone(true).attr('id','additional').find('.group:first').remove().end().find('script').remove().end().find('style').remove().end().find('[style="border: none;"]').removeAttr('style').end();
var c = jQuery('#content').clone(true).attr('id','additional').find('.group:first').remove().end().find('script').remove().end().find('style').remove().end().find('[style="border: none;"]').removeAttr('style').end().html().replace(/\n|\r|(\s\s)/g,'');
var d = '<div class="group"></div>' == c;
var e = (!d) ? b : false;
你会如何处理的情况下,如果脚本标记中的JavaScript插入可见的内容到DIV? – 2012-07-09 23:18:06
为什么'img'或'script' * not *会成为内容?你基于什么标准? – 2012-07-09 23:22:59
@SaniHuttunen伟大的观点,这就是我想弄明白! – ThomasReggi 2012-07-09 23:45:46