我有以下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