我有点坚持用jQuery重新排序问题。在followng代码中,structre就像输入> label> div,但是我需要先放置div,然后在最新元素中标记和输入。
正如你所看到的那样,标签元素没有id ...所以我有点卡在这里:( 有什么帮助吗?
<div class="taxonomy" id="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency">
<ul class="taxonomy_radiobuttons">
<li class="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_Notsmoking">
<input type="radio" value="//wwx/6000 Context/Daily smoking frequency.model#NotSmoking" name="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency" id="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_Notsmoking">
<label for="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_Notsmoking">.Not smoking</label>
<div class="visual"><p><img src="/myapp/resources/dynamic/7139b8eb"></p></div>
</li>
<li class="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_0005">
<input type="radio" value="//wwx/6000 Context/Daily smoking frequency.model#HalfPacket" name="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency" id="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_0005">
<label for="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_0005">0,0-0,5</label>
<div class="visual"><p><img src="/myapp/resources/dynamic/49b8660"></p></div>
</li>
<li class="wwx5000InstrumentsPriceandconditions.model#PriceAndConditions.classifies__InputObjectType_0_DailySmokingFrequency_0510">
<input type="radio" value="//wwx/6000 Context/Daily smoking frequency.model#OnePacket" name="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency" id="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_0510">
<label for="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_0510">0,5-1,0</label>
<div class="visual"><p><img src="/myapp/resources/dynamic/7e930afc"></p></div>
</li>
<li class="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_1015">
<input type="radio" value="//wwx/6000 Context/Daily smoking frequency.model#OneAndHalfPacket" name="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency" id="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_1015">
<label for="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_1015">1,0-1,5</label>
<div class="visual"><p><img src="/myapp/resources/dynamic/67b6674f"></p></div>
</li>
<li class="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_1520">
<input type="radio" value="//wwx/6000 Context/Daily smoking frequency.model#TwoPacket" name="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency" id="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_1520">
<label for="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_1520">1,5-2,0</label>
<div class="visual"><p><img src="/myapp/resources/dynamic/7838a8ba"></p></div>
</li>
<li class="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_20">
<input type="radio" value="//wwx/6000 Context/Daily smoking frequency.model#MoreThanTwoPacket" name="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency" id="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_20">
<label for="wwx5000Instrumentsconditions.model#Conditions.classifies__InputObjectType_0_DailySmokingFrequency_20">>2,0</label>
<div class="visual"><p><img src="/myapp/resources/dynamic/4fcd88ff"></p></div>
</li>
</ul>
答案 0 :(得分:1)
我自己的建议:
$('.taxonomy_radiobuttons li').each(function(){
var self = $(this),
d = self.find('div'),
i = self.find('input'),
l = self.find('label');
d.prependTo(self);
l.appendTo(self);
});
答案 1 :(得分:1)
你可以这样做:
$('.taxonomy ul li > input').before(function(){
return $(this).siblings('.visual');
});
<强> Fiddle 强>
before接受一个函数参数来返回要在所选元素之前插入的元素,在函数中返回div,它是所选输入的兄弟。
答案 2 :(得分:0)
(已编辑)尝试:http://jsfiddle.net/bCvbu/
$('li').each(function() {
$div = $(this).find('div');
$label = $(this).find('label');
$input = $(this).find('input');
$(this).html('');
$(this).append($div, $label, $input);
});