这是一个创建于 2915 天前的主题,其中的信息可能已经有所发展或是发生改变。
页面里有好几个 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
![cxlxkin](https://cdn.v2ex.com/avatar/5d5a/f481/145621_normal.png?m=1446565788) |
|
2
cxlxkin 2016-07-12 16:53:07 +08:00
学编程不能让别人帮你写,别人提供思路,自己去摸索写,这样才能学到东西的
|
![cxbig](https://cdn.v2ex.com/avatar/5d08/eaa4/23163_normal.png?m=1441656972) |
|
4
cxbig 2016-07-12 17:03:48 +08:00 1
这题目也是奇葩,这年头还在折腾 HTML DOM Style 。
|
![tester4](https://cdn.v2ex.com/gravatar/1a5dc15f6c29d58f0c9926682f34c177?s=48&d=retro) |
|
5
tester4 2016-07-12 17:06:06 +08:00
|
![cxlxkin](https://cdn.v2ex.com/avatar/5d5a/f481/145621_normal.png?m=1446565788) |
|
6
cxlxkin 2016-07-12 17:07:43 +08:00
|
![cxbig](https://cdn.v2ex.com/avatar/5d08/eaa4/23163_normal.png?m=1441656972) |
|
8
cxbig 2016-07-12 17:13:06 +08:00
@ tester4 不要浪费时间在这种无意义的实现上
|
![tester4](https://cdn.v2ex.com/gravatar/1a5dc15f6c29d58f0c9926682f34c177?s=48&d=retro) |
|
10
tester4 2016-07-12 17:13:40 +08:00 1
|
![issuz](https://cdn.v2ex.com/avatar/b120/da29/164781_normal.png?m=1459325874) |
|
11
issuz 2016-07-12 17:17:44 +08:00
$('.post .postid').each(function(){ $(this).closest('.post').css('color',$(this).css('color')); })
|
![tester4](https://cdn.v2ex.com/gravatar/1a5dc15f6c29d58f0c9926682f34c177?s=48&d=retro) |
|
12
tester4 2016-07-12 17:18:49 +08:00
|
![tester4](https://cdn.v2ex.com/gravatar/1a5dc15f6c29d58f0c9926682f34c177?s=48&d=retro) |
|
13
tester4 2016-07-12 17:20:58 +08:00
|
![issuz](https://cdn.v2ex.com/avatar/b120/da29/164781_normal.png?m=1459325874) |
|
14
issuz 2016-07-12 17:22:04 +08:00 via iPhone
|