Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.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
Javascript CSS选择器中列表值的While循环迭代_Javascript_Css_Loops_While Loop - Fatal编程技术网

Javascript CSS选择器中列表值的While循环迭代

Javascript CSS选择器中列表值的While循环迭代,javascript,css,loops,while-loop,Javascript,Css,Loops,While Loop,在下面的内容中,我想迭代while循环中“month”变量中可用的值。 当我尝试时,它将信息显示为“期望整数值” if(selectedForYear()==2016){ var d=新日期(); var month=d.getMonth(); 虽然(月尝试使用parseInt(),但缺少的是与变量的连接。您需要将变量的值与选择器连接起来 $('.accordionContent .flexContent .dk_options li:nth-child('+ parseInt(month)+'

在下面的内容中,我想迭代while循环中“month”变量中可用的值。 当我尝试时,它将信息显示为“期望整数值”

if(selectedForYear()==2016){
var d=新日期();
var month=d.getMonth();
虽然(月尝试使用
parseInt()
,但缺少的是与变量的连接。您需要将变量的值与选择器连接起来

$('.accordionContent .flexContent .dk_options li:nth-child('+ parseInt(month)+')').css({ "display": 'none' });
两个错误:

month
不能在字符串literal
…第n个子(月)
内。此外,您可能希望增加
month
,而不是
n

while (month <= 11) {
  $('.accordionContent .flexContent .dk_options li:nth-child(' + month + ')').css({ "display": 'none' });
  month ++;
}

虽然(此处的月份
('.accordiocontent.flexContent.dk_options li:n子项(月)
,但月份未指向变量
month
,而是被视为字符串
month
,请尝试此
('.accordiocontent.flexContent.dk_options li:n子项('+month+'))
@Rajesh它不起作用。当我像上面那样尝试时,我无法在下拉列表中选择特定值“2016”。它不起作用。当我像上面那样尝试时,我无法在UI的下拉列表中选择特定值“2016”。
while (month <= 11) {
  $('.accordionContent .flexContent .dk_options li:nth-child(' + month + ')').css({ "display": 'none' });
  month ++;
}