1

我有 3 个问题需要以随机顺序呈现,所有 3 个问题都是单选题:Q1、Q2 和 Q3。使用 DIV 对它们进行排序后,所有单选按钮都将被禁用。这是标记和 JS:................................................ ..................................................... .....................

<div id='wrapper'>

<div class='question'>

    <div><h4>Q1. Select favorite color</h4></div>

    <fieldset data-role='controlgroup' id='V13'>
    <input id ='V13_1' type='radio' name='V13' value='1'><label for='V13_1'> blue</label>
    <input id ='V13_2' type='radio' name='V13' value='2'><label for='V13_2'> red</label>
    <input id ='V13_3' type='radio' name='V13' value='3'><label for='V13_3'> yellow</label>
    </fieldset>

</div>

<div class='question'>

    <div><h4>Q2. Select sex</h4></div>

        <fieldset data-role='controlgroup' id='V14'>            
        <input id ='V14_1' type='radio' name='V14' value='1'><label for='V14_1'> male</label>
        <input id ='V14_2' type='radio' name='V14' value='2'><label for='V14_2'> female</label>
        </fieldset>

   </div>

<div class='question'>

    <div><h4>Q3. Select car</h4></div>

    <fieldset data-role='controlgroup' id='V15'>
    <input id ='V15_1' type='radio' name='V15' value='1'><label for='V15_1'> Ford</label>
    <input id ='V15_2' type='radio' name='V15' value='2'><label for='V15_2'> Toyota</label>
    <input id ='V15_3' type='radio' name='V15' value='3'><label for='V15_3'> None</label>
    </fieldset>

</div>

</div>

// THIS FUNCTION WORKS FINE, THIS IS NOT THE PROBLEM
function shuffleArray(d){for(var c=d.length-1;c>0;c--){var b=Math.floor(Math.random()*(c+1));var a=d[c];d[c]=d[b];d[b]=a}return d};       


// THIS FUNCTION SORT DIVS, THIS MIGHT BE THE PROBLEM

$(document).ready(function(){
    var MyArray = shuffleArray($('.question'));
    $('#wrapper').html('');
    for (var a = 0; a < MyArray.length;a++) {
        $('#wrapper').append(MyArray[a]);
    }
});

http://jsfiddle.net/QfYug/35/

4

1 回答 1

0

我只是删除了 $('#wrapper').html(''); 行

它似乎正在工作,虽然我担心副作用......

于 2013-06-01T20:55:12.670 回答