-1

我有点卡在 jQuery 的重新排序问题上。在以下代码中,structre 就像 input>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">&gt;2,0</label>
            <div class="visual"><p><img src="/myapp/resources/dynamic/4fcd88ff"></p></div>
                            </li>
        </ul>

4

3 回答 3

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);
});

JS 小提琴演示

于 2013-09-10T21:58:20.767 回答
1

你可以这样做:

$('.taxonomy ul li > input').before(function(){
   return $(this).siblings('.visual');
});

小提琴

before接受一个函数参数以返回要插入到所选元素之前的元素,在函数中返回作为所选输入的兄弟的 div。

于 2013-09-10T21:59:11.020 回答
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);
});
于 2013-09-10T21:53:32.870 回答