나는 다음과 같은 div
을 가지고 있으며, 다음과 같은 것을 가지고있다. children
.보이는 내용이없는 요소
<div>
<img src="http://zferral.com">
<!--zferral is an invisible image analytics tool-->
<script>Some Comment</script>
</div>
이 항목에는 3 가지가 있습니다. 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>
내 진행
나는 DIV 모든 스크립트 태그를 제거 찾을 복사 .clone()
을 사용했다.
모든 주석을 구문 분석하고 제거하려면 regex를 사용해야합니다.
그런 다음 regex와 .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;
이 어떻게 사건을 처리 할 것인가? –
왜'img' 또는'script' *는 만족하지 않습니까? 그 기준은 무엇입니까? –
@SaniHuttunen 위대한 포인트 그게 뭔지 알아 내려고있어! – ThomasReggi