tester4
V2EX  ›  jQuery

新手问个问题呗?

  •  
  •   tester4 · Jul 12, 2016 · 3798 views
    This topic created in 3617 days ago, the information mentioned may be changed or developed.
    页面里有好几个 div
    <div class="post"><span class="postid" style="color:fff"></span></div>
    <div class="post"><span class="postid" style="color:888"></span></div>
    <div class="post"><span class="postid" style="color:ccc"></span></div>

    想让 post 里的 color 跟 postid 里的一样,咋写?

    if ($('div.post .postid').hasClass("color")) {
    $('div.post').addClass("color");
    }

    var cc = $('div.post .postid').css("color");
    $this('div.post').css(cc);
    ??????
    具体怎么写?我不太会,帮我写一个呗?谢啦~万分感谢。
    14 replies    2016-07-12 17:22:04 +08:00
    BrightDawn
        1
    BrightDawn  
       Jul 12, 2016
    cxlxkin
        2
    cxlxkin  
       Jul 12, 2016
    学编程不能让别人帮你写,别人提供思路,自己去摸索写,这样才能学到东西的
    cxbig
        4
    cxbig  
       Jul 12, 2016   ❤️ 1
    这题目也是奇葩,这年头还在折腾 HTML DOM Style 。
    tester4
        5
    tester4  
    OP
       Jul 12, 2016
    @BrightDawn
    @cxlxkin
    @b821025551b

    谢谢你们这些最可爱的人
    cxlxkin
        6
    cxlxkin  
       Jul 12, 2016
    @tester4 so 要一起讨论哲学?
    tester4
        7
    tester4  
    OP
       Jul 12, 2016
    @cxlxkin
    @cxbig
    原来 V2 是个专门吐槽的网站,终于整明白了。
    cxbig
        8
    cxbig  
       Jul 12, 2016
    @tester4 不要浪费时间在这种无意义的实现上
    cxlxkin
        9
    cxlxkin  
       Jul 12, 2016
    @tester4 不是啦,只是这个我不会而已。。。嘿嘿嘿
    tester4
        10
    tester4  
    OP
       Jul 12, 2016   ❤️ 1
    @cxbig 不要浪费时间在 V2 才是现实。
    issuz
        11
    issuz  
       Jul 12, 2016
    $('.post .postid').each(function(){
    $(this).closest('.post').css('color',$(this).css('color'));
    })
    tester4
        12
    tester4  
    OP
       Jul 12, 2016
    @issuz 谢啦,好人啊,内牛满面,我先试试。
    tester4
        13
    tester4  
    OP
       Jul 12, 2016
    @issuz 试了,好使,非常非常感谢。
    issuz
        14
    issuz  
       Jul 12, 2016 via iPhone
    @tester4 不客气
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 01:53 · PVG 09:53 · LAX 18:53 · JFK 21:53
    ♥ Do have faith in what you're doing.