新手问个问题呗?

2016-07-12 16:42:03 +08:00
 tester4
页面里有好几个 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);
??????
具体怎么写?我不太会,帮我写一个呗?谢啦~万分感谢。
2949 次点击
所在节点    jQuery
14 条回复
BrightDawn
2016-07-12 16:52:28 +08:00
cxlxkin
2016-07-12 16:53:07 +08:00
学编程不能让别人帮你写,别人提供思路,自己去摸索写,这样才能学到东西的
b821025551b
2016-07-12 16:55:18 +08:00
cxbig
2016-07-12 17:03:48 +08:00
这题目也是奇葩,这年头还在折腾 HTML DOM Style 。
tester4
2016-07-12 17:06:06 +08:00
@BrightDawn
@cxlxkin
@b821025551b

谢谢你们这些最可爱的人
cxlxkin
2016-07-12 17:07:43 +08:00
@tester4 so 要一起讨论哲学?
tester4
2016-07-12 17:09:45 +08:00
@cxlxkin
@cxbig
原来 V2 是个专门吐槽的网站,终于整明白了。
cxbig
2016-07-12 17:13:06 +08:00
@tester4 不要浪费时间在这种无意义的实现上
cxlxkin
2016-07-12 17:13:21 +08:00
@tester4 不是啦,只是这个我不会而已。。。嘿嘿嘿
tester4
2016-07-12 17:13:40 +08:00
@cxbig 不要浪费时间在 V2 才是现实。
issuz
2016-07-12 17:17:44 +08:00
$('.post .postid').each(function(){
$(this).closest('.post').css('color',$(this).css('color'));
})
tester4
2016-07-12 17:18:49 +08:00
@issuz 谢啦,好人啊,内牛满面,我先试试。
tester4
2016-07-12 17:20:58 +08:00
@issuz 试了,好使,非常非常感谢。
issuz
2016-07-12 17:22:04 +08:00
@tester4 不客气

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/291990

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX