在一项调查中,我需要显示几个以随机方式显示的复选框,但其中一个必须是静止的,因为例如我需要捕获文本
What is your favorite color?
( ) Red
( ) Yellow
( ) Blue
Other, please specify:____________________
--------------
What is your favorite color?
( ) Yellow
( ) Red
( ) Blue
( ) Other, please specify:____________________
--------------
What is your favorite color?
( ) Blue
( ) Yellow
( ) Red
( ) Other, please specify:____________________
我有一个有效的代码,但我不能保留最后一个选项......
<!DOCTYPE html>
<html>
<head>
<link href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<meta charset=utf-8 />
<title>Semi-Random Checkboxes</title>
</head>
<body>
<fieldset id="checkboxes" data-role="controlgroup">
<label><input type="checkbox" value="red">Red</label>
<label><input type="checkbox" value="blue">Blue</label>
<label><input type="checkbox" value="yellow">Yellow</label>
<label><input type="checkbox" value="Other">Other, specify</label><input type="text" value="text">
</fieldset>
<script>
(function($) {
var container = $("#checkboxes");
var cbs = container.children("label");
var index;
for (index = 0; index < cbs.length; ++index) {
$(cbs[Math.floor(Math.random() * cbs.length)]).appendTo(container);
}
})(jQuery);
</script>
</body>
</html>