使用javascript在html选择“选项”标记中循环,不给出结果

dwthyt8l  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(368)

我试图在javascript中循环html选择。下面是我的代码。我想在选项中显示我的计数值。我从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");
nafvub8i

nafvub8i1#

检查一下这个也许对你有帮助

<!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>

相关问题