jquery选择器不能用于:condition

时间:2017-09-21 20:46:02

标签: jquery css

Jquery选择器不适用于not:条件。 我想选择没有图片且位于divs内的div#loccontPck。 之后,我计划将borderpaddingmargin应用于他们。

这是选择器:

$( '#loccontPck div:not(:has(img)' ).each( function() { oiDivArr.push( $(this) ); } ); 

这是结果

   [div.pckItem]
   [div#mapImg.mapImg]
   [div.pckItem.imgFall_1.imgPckiCar] 

正确的结果是:

   [div.pckItem]
   [div.pckItem]
   [div.pckItem]

这是html:

<div class="pck" id="loccontPck">

    <!-- map --><div class="pckItem" style="margin-top: 5.94444px;"><h2 style="margin-top: 0.775362px;"> Διεύθυνση </h2>
    <p> Δρόμος 5,3086,Kiti,Larnaka,Cyprus </p>
    <div id="mapImg" class="mapImg" style="margin-top: 5.94444px;">
    <img id="trustMap" src="https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/trustMap.PNG" sizes="(max-width:  561px) 100vw, 50vw" srcset="https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/trustMap.PNG 200w, 
            https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/trustMap.PNG 400w,
            https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/trustMap.PNG 600w" style="border-top: 0px solid white; border-bottom: 3.56667px solid white; padding-top: 3.56667px; padding-bottom: 0px; margin-top: 3.56667px; height: 392.192px;">
     </div><a class="menulink map" href="https://typejoy.biz/dev/personex4/gr/certifoff2map">Δείτε διαδραστικό μεγάλο χάρτη</a>

    </div><!-- map -->



    <!-- contacts --><div class="pckItem" style="margin-top: 5.94444px;"><h2 style="margin-top: 0.775362px;"> Επαφές </h2>
    <p> TEL: +357 1234 5647 </p>
    <p> Ταχυδρομείο:
    officer.cy@gmail.com
    secretary.cy@gmail.com
    </p>

    <a class="menulink contact" href="https://typejoy.biz/dev/personex4/gr/certifoff2contact">Χρησιμοποιήστε τη φόρμα επικοινωνίας</a> 

    <h2 style="margin-top: 0.775362px;"> Ωρες εργασίας </h2>
    <p> 24ωρη εξυπηρέτηση, 7 ημέρες την εβδομάδα </p>

    <h2 style="margin-top: 0.775362px;"> Γλώσσες </h2>
    <p> Αγγλικά, Ελληνικά, Ρωσικά </p>

    <p></p><div class="froww" style="margin-top: 5.94444px;">​
    <!-- C:\Bitnami\wampstack-7.0.22-1\apache2\htdocs\type70823\public\js\ViewFncJs\social.js -->
    <a class="facebookBtnRnd bfBtnRnd fisoc" href="social-media-profile-url" id="fbShare"></a><p class="socMsg">Share on facebook</p>
    <a class="twitterBtnRnd bfBtnRnd fisoc" href="social-media-profile-url" id="twitterShare"></a><p class="socMsg">Share on Twitter</p>
    <a class="googleplusBtnRnd bfBtnRnd fisoc" href="social-media-profile-url" id="gplusShare"></a><p class="socMsg">Share on google+</p>
    <a class="vkShareBtnRnd bfBtnRnd fisoc" href="social-media-profile-url" id="vkShare"></a><p class="socMsg">Share on VKontact</p>
    <a class="linkedinShareBtnRnd bfBtnRnd fisoc" href="social-media-profile-url" id="linkedinShare"></a><p class="socMsg">Share on Linkedin</p>  
    <!--  .socMsg { display : none}    a.bfBtnRnd:hover + .socMsg {display:block;}  -->

    </div><p></p>

    </div><!-- contacts -->




    <!-- fallback photo for streching, on resizing is only 50px height --><div class="pckItem imgFall_1 imgPckiCar" style="margin-top: 5.94444px;"><img id="pexels-photo-193021" src="https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/pexels-photo-193021_1240.jpg" sizes="(max-width:  561px) 100vw, 50vw" srcset="https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/pexels-photo-193021_300.jpg 200w,
            https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/pexels-photo-193021_560.jpg 300w, 
            https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/pexels-photo-193021_800.jpg 400w, 
            https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/pexels-photo-193021_1040.jpg 550w, 
            https://typejoy.biz/exm/about/about170821b/public/img/HotColImgBundleIMG/red/pexels-photo-193021_1240.jpg 700w"> 
    </div><!-- fallback photo for streching, on resizing is only 50px height -->



</div> <!--   div class="pck" id="loccontPck"   -->

2 个答案:

答案 0 :(得分:1)

$( '#loccontPck div' ).not(':has(img)').each( function() { oiDivArr.push( $(this) ); } ); 

答案 1 :(得分:-1)

我错过了2条件的结束括号:)

firstkey, secondkey, 3, [8,2]