如何在一个随机化的有序列表中随机化多个无序列表
How do I randomize multiple unordered lists within a randomized ordered list?
我正试图用包含随机答案(随机化无序列表)的随机问题(随机化有序列表)进行测试。我可以让有序列表随机化,但我只能让一个无序列表随机化。该代码只对它找到的第一个无序列表进行随机化。我想把所有无序的列表都随机化。感谢您的帮助。
<ol>
<li>What are the three main areas of the Standard User Interface?
<ul type="none">
<li><input type="radio" name="q1" value="0" />A. Header, Banner, Frame, Application Window</li>
<li><input type="radio" name="q1" value="0" />B. Content Frame, Homepage, Form </li>
<li><input type="radio" name="q1" value="1" />C. Application Navigator, Banner Frame, Content Frame </li>
<li><input type="radio" name="q1" value="0" />D. None of the above</li>
</ul>
</li>
<li>In the User interface, what is the gray toolbar called which allows you to add bookmarks?<br/>
<ul type="none">
<li><input type="radio" name="g2" value="0" />A. Gauge</li><br />
<li><input type="radio" name="g2" value="1" />B. Edge</li><br />
<li><input type="radio" name="g2" value="0" />C. Remedy</li><br />
<li><input type="radio" name="g2" value="0" />D. Banner</li><br />
</ul><br/>
</li>
<li>What can be captured in an update set?<br/>
<ul type="none">
<li><input type="radio" name="g3" value="0" />A. Modified CI Rules</li><br />
<li><input type="radio" name="g3" value="1" />B. Business Rules</li><br />
<li><input type="radio" name="g3" value="0" />C. Scheduled Jobs</li><br />
<li><input type="radio" name="g3" value="0" />D. None of the above</li><br />
</ul>
</li>
<li>What should you always do before you commit an update set?<br/>
<ul type="none">
<li><input type="radio" name="g4" value="1" />A. Preview</li><br />
<li><input type="radio" name="g4" value="0" />B. Merge</li><br />
<li><input type="radio" name="g4" value="0" />C. Ignore</li><br />
<li><input type="radio" name="g4" value="0" />D. All of the above</li><br />
</ul>
</li>
<li>Which of the following is a Business Rule best pratice?<br/>
<ul type="none">
<li><input type="radio" name="g5" value="1" />A. Make business rules small and specific</li><br />
<li><input type="radio" name="g5" value="0" />B. Use of conditions is not necessary</li><br />
<li><input type="radio" name="g5" value="0" />C. Global business rules should be used</li><br />
<li><input type="radio" name="g5" value="0" />D. None of the above</li><br />
</ul>
</li>
<li>Which of the following is a Client Script best practice?<br/>
<ul type="none">
<li><input type="radio" name="g6" value="0" />A. Use hard coded data</li><br />
<li><input type="radio" name="g6" value="0" />B. Maximize server lookup</li><br />
<li><input type="radio" name="g6" value="1" />C. Do not use g_form.getReference()</li><br />
<li><input type="radio" name="g6" value="0" />D. All of the above</li><br />
</ul>
</li>
<li>Which of the following are debugging features?<br/>
<ul type="none">
<li><input type="radio" name="g7" value="0"/>A. Debug Business Rule</li><br />
<li><input type="radio" name="g7" value="0"/>B. Javascript</li><br />
<li><input type="radio" name="g7" value="1"/>C. A and B</li><br />
<li><input type="radio" name="g7" value="0"/>D. None of the above</li><br />
</ul>
</li>
</ol>
这是我的随机化代码:
var ol = document.querySelector('ol');
temp = ol.cloneNode(true);
for (var i = temp.children.length; i--; ){
temp.appendChild( temp.children[Math.random() * i |0] );
ul.parentNode.replaceChild(temp, ol);
}
var ul = document.querySelector('ul');
temp = ul.cloneNode(true);
for (var i = temp.children.length + 1; i--; ){
temp.appendChild( temp.children[Math.random() * I |0] );
ul.parentNode.replaceChild(temp, ul);
}
document.querySelector()
适用于ol
元素,因为只有一个。要捕获ul
,请使用querySelectorAll
并循环通过其值。还有一个问题是ol
和ul
的父节点丢失。parentNode.replaceChild...
语句必须在for
循环之后,而不是在其中。在querySelectorAll
值的循环中,必须备份父节点;请参阅在javascript 中设置父节点
var ol = document.querySelector('ol');
temp = ol.cloneNode(true);
for (var i = temp.children.length; i--;) {
temp.appendChild(temp.children[Math.random() * i | 0]);
}
ol.parentNode.replaceChild(temp, ol);
var ul = document.querySelectorAll('ul'), parent;
console.log("found " + ul.length + " ul's");
for (var k = ul.length-1; k >= 0; k--) {
parent = ul[k].parentNode;
temp = ul[k].cloneNode(true);
for (var i = temp.children.length + 1; i--;) {
temp.appendChild(temp.children[Math.random() * i | 0]);
}
parent.replaceChild(temp, ul[k]);
}
相关文章:
- $(document).height()在刷新时随机化值(Safari 5.1.10)
- 如何随机显示列表项的顺序
- 将键盘使用与 Qualtrics 中的答案随机化相结合
- 我怎样才能随机化 HTML 元素的颜色属性
- 通过AJAX调用PHP随机化器的输出
- 如何在JS中随机化backgroundPosition而不使用鼠标移动来制作万花筒的动画
- 如何避免/最小化列表中列表的缩进
- 从字符串行创建结构化列表
- 如何使用搜索筛选器初始化列表视图
- 使用Javascript对RGBA颜色进行光标控制的形状随机化
- 如何在一个随机化的有序列表中随机化多个无序列表
- 如何使用JavaScript随机化有序列表
- 使用JavaScript随机化html标记
- 可以'我的单词随机化器脚本不能正常循环
- 从1-9之间的随机数字列表中选出3个相同的数字
- 如果语句是假的 JavaScript,则再次随机化数字
- 函数随机化 - 我可以让它错过一个页面并且该页面上只有一个图像吗?可湿性粉剂
- 随机化网页上的图像和颜色对
- PHP 从现有代码中随机化文件列表数组
- 将无序列表随机化