我有一个表格问题,询问您是否饮酒、吸毒,两者都没有,“777”、“999”。
alcohol : question 2; drugs : question 3; both : questions 2 + 3; neither or "777" or "999" : question 4.
我有一个 jquery change() 监听设置(并且正在工作),并且我有一个 switch 语句设置并且大部分都在工作,除了 ||"777"||"999"
。在 case "neither..."
中,我有一个数组 vices
和一个 for...in
循环。我的假设是 for…in
的功能类似于/类似于 php 的 foreach
。
在隐藏问题并将其值设置为不适用之前,我需要检测问题是否尚未已非事件
(所以我知道这是有目的的而不是让它空着)。
case "neither" || "777" || "999":
var vices = new Array('alcohol','drugs');
for ( vice in vices ) {
if ( $("ul#vice").hasClass("inactive") == false ) {
$("ul#vice").append('<input name="'+vice+'" type="radio" value="not applicable" checked="checked" />');
$("ul#vice").delay(250).queue( function() {$(this).addClass("inactive");queue()} );
}
}
我认为问题与 $("ul#vice")
有关,但我不确定。 (我已经尝试过 $("ul#"+vice)
,但这也不起作用)。
问题看起来像:
.inactive{display:none; z-index:-5}
#
<ul id="alcohol" class="inactive">How many alcoholic drinks do you have?
<li><input name="alcohol" type="text" maxlength="2" /><span id="alcohol" class="inactive"></span></li>
<li><input name="alcohol" type="radio" value="777" />Don't know</li>
<li><input name="alcohol" type="radio" value="999" />Prefer to not answer</li>
<input name="alcohol" type="radio" value="not applicable" checked="checked" />
</ul>
提前致谢!
最佳答案
您认为 for...in
与 foreach
... 类似的假设是错误的。
关于javascript for...in + if-test(在表单内的开关内部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7235335/