Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery移动随机输入_Jquery_Jquery Mobile - Fatal编程技术网

Jquery移动随机输入

Jquery移动随机输入,jquery,jquery-mobile,Jquery,Jquery Mobile,我需要使用JQM以一种随机的方式呈现输入 我想我应该使用div来分隔每个问题,然后调用JavaScrip func进行排序,但不知道如何进入 第一季度、第三季度、第二季度。。。 第一季度、第二季度、第三季度。。。 第三季度、第二季度、第一季度。。。 等 像这样: Q1. What is your age? (Number) Q2. What color do you prefer? (Single choice) Q2. Tell us about the food...(Group) 以下是

我需要使用JQM以一种随机的方式呈现输入

我想我应该使用div来分隔每个问题,然后调用JavaScrip func进行排序,但不知道如何进入

第一季度、第三季度、第二季度。。。 第一季度、第二季度、第三季度。。。 第三季度、第二季度、第一季度。。。 等

像这样:

Q1. What is your age? (Number)
Q2. What color do you prefer? (Single choice)
Q2. Tell us about the food...(Group)
以下是加价:

<div>
    <h4>Q1. What is your age?</h4>
</div>

    <input name='V14' id='V14' data-default-value='0' type='number' min='0' max='100' size='12' step='0.1' class=''/>

<div>
    <h4>Q2. What color do you prefer</h4>
</div>

<fieldset data-role='controlgroup' id='V15'>

<input id ='V15_1' type='radio' name='V15' value='1'><label for='V15_1'> Blue</label>
<input id ='V15_2' type='radio' name='V15' value='2'><label for='V15_2'> Red</label>
<input id ='V15_3' type='radio' name='V15' value='3'><label for='V15_3'> Yellow</label>
</fieldset>


<div>
    <h4>Q3. Tell us about the food</h4>
</div>

<div data-role='collapsible-set'>
<div data-role='collapsible' data-collapsed='false' data-theme='b' data-content-theme='d'>
<h3>Flavour</h3>

    <fieldset data-role='controlgroup' id='V16'>
    <input id ='V16_1' type='radio' name='V16' value='1'><label for='V16_1'> Good</label>
    <input id ='V16_2' type='radio' name='V16' value='2'><label for='V16_2'> Fair</label>
    </fieldset>
</div>
</div>

<div data-role='collapsible-set'>
<div data-role='collapsible' data-collapsed='false' data-theme='b' data-content-theme='d'>
<h3>Taste</h3>

    <fieldset data-role='controlgroup' id='V17'>
    <input id ='V17_1' type='radio' name='V17' value='1'><label for='V17_1'> Good</label>
    <input id ='V17_2' type='radio' name='V17' value='2'><label for='V17_2'> Fair</label>
    </fieldset>
</div>
</div>

<div data-role='collapsible-set'>
<div data-role='collapsible' data-collapsed='false' data-theme='b' data-content-theme='d'>
<h3>Temperature</h3>
    <fieldset data-role='controlgroup' id='V18'>
    <input id ='V18_1' type='radio' name='V18' value='1'><label for='V18_1'> Good</label>
    <input id ='V18_2' type='radio' name='V18' value='2'><label for='V18_2'> Fair</label>
    </fieldset>
</div>
</div>

问题1。你几岁?
问题2。你喜欢什么颜色
蓝色
红色
黄色的
第三季度。告诉我们关于食物的事
风味
好
公平的
品味
好
公平的
温度
好
公平的

基本上,只需将您的问题包装到单独的div中,然后按以下步骤进行操作:

<div id="wrapper">
    <div class="question">
    question1
    </div>

    <div class="question">
    question2
    </div>

    <div class="question">
    question3
    </div>
</div>

<script type="text/javascript">
    function shuffle(array) {
        var counter = array.length, temp, index;

        // While there are elements in the array
        while (--counter > -1) {
            // Pick a random index
            index = (Math.random() * counter) | 0;

            // And swap the last element with it
            temp = array[counter];
            array[counter] = array[index];
            array[index] = temp;
        }

        return array;
    }

    var shuffled = shuffle($('.question'));
    $('#wrapper').html('');

    for (var a = 0; a < shuffled.length;a++) {
        $('#wrapper').append(shuffled[a]);
    }
</script>

问题1
问题2
问题3
函数洗牌(数组){
变量计数器=数组长度、温度、索引;
//当数组中有元素时
而(--计数器>-1){
//选择一个随机索引
索引=(Math.random()*计数器)| 0;
//并用它交换最后一个元素
温度=阵列[计数器];
数组[计数器]=数组[索引];
数组[索引]=温度;
}
返回数组;
}
var shuffled=shuffle($('.question'));
$('#wrapper').html('');
for(var a=0;a

洗牌功能很好地借鉴了

希望能有帮助