V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tester4
V2EX  ›  jQuery

新手问个问题呗?

  •  
  •   tester4 · 2016-07-12 16:42:03 +08:00 · 2847 次点击
    这是一个创建于 2842 天前的主题,其中的信息可能已经有所发展或是发生改变。
    页面里有好几个 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 条回复    2016-07-12 17:22:04 +08:00
    BrightDawn
        1
    BrightDawn  
       2016-07-12 16:52:28 +08:00
    cxlxkin
        2
    cxlxkin  
       2016-07-12 16:53:07 +08:00
    学编程不能让别人帮你写,别人提供思路,自己去摸索写,这样才能学到东西的
    b821025551b
        3
    b821025551b  
       2016-07-12 16:55:18 +08:00
    cxbig
        4
    cxbig  
       2016-07-12 17:03:48 +08:00   ❤️ 1
    这题目也是奇葩,这年头还在折腾 HTML DOM Style 。
    tester4
        5
    tester4  
    OP
       2016-07-12 17:06:06 +08:00
    @BrightDawn
    @cxlxkin
    @b821025551b

    谢谢你们这些最可爱的人
    cxlxkin
        6
    cxlxkin  
       2016-07-12 17:07:43 +08:00
    @tester4 so 要一起讨论哲学?
    tester4
        7
    tester4  
    OP
       2016-07-12 17:09:45 +08:00
    @cxlxkin
    @cxbig
    原来 V2 是个专门吐槽的网站,终于整明白了。
    cxbig
        8
    cxbig  
       2016-07-12 17:13:06 +08:00
    @tester4 不要浪费时间在这种无意义的实现上
    cxlxkin
        9
    cxlxkin  
       2016-07-12 17:13:21 +08:00
    @tester4 不是啦,只是这个我不会而已。。。嘿嘿嘿
    tester4
        10
    tester4  
    OP
       2016-07-12 17:13:40 +08:00   ❤️ 1
    @cxbig 不要浪费时间在 V2 才是现实。
    issuz
        11
    issuz  
       2016-07-12 17:17:44 +08:00
    $('.post .postid').each(function(){
    $(this).closest('.post').css('color',$(this).css('color'));
    })
    tester4
        12
    tester4  
    OP
       2016-07-12 17:18:49 +08:00
    @issuz 谢啦,好人啊,内牛满面,我先试试。
    tester4
        13
    tester4  
    OP
       2016-07-12 17:20:58 +08:00
    @issuz 试了,好使,非常非常感谢。
    issuz
        14
    issuz  
       2016-07-12 17:22:04 +08:00 via iPhone
    @tester4 不客气
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5805 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 62ms · UTC 02:20 · PVG 10:20 · LAX 19:20 · JFK 22:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.