我正在尝试在JavaScript中的HTML Select中循环。下面是我的代码。我想在选项中显示我的COUNT值。我正在从PHP端获取一些数据;它需要显示计数。请告知我是否遗漏了什么或是错误的方式?
var cjs=$form.find('[name="cjs"]').data("cjs");
var newHtml = 'Current<br>
<select class="form-control" id="priority" name="priority">
'+for (var i = 1; i <= cjs; i++) {+'
<option disabled selected value ="0" style="display:none">-CHOOSE PRIORITY-</option>
'+}+'
</select>
<button class=" upr edit btn btn-sm btn-primary"> Update </button></center></div>';
$('.proo'+request).html(newHtml);
alert("Successfully Updated");
检查一下这可能会对你的有所帮助
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Date Picker</title>
</head>
<body>
<p>Click the button to loop through a block of code five times.</p>
<select id="demo">
</select>
<p id="demo"></p>
<script>
function myFunction(selector)
{
var optionList="CHOOSE PRIORITY "
var i;
for (i=1;i<=5;i++){
selector.options[i-1] = new Option(optionList+i);
}
}
//usage:
myFunction(document.getElementById("demo"));
</script>
</body>
</html>