var delivery_nums = ($("#delivery_num").val()).split(",");
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
for (var num =0 ; num < delivery_nums.length ; num++ ) {
var input = '<div class="delivery-num-input">';
input += "<input type='text' pattern='[0-9]+'\
class='form-control delivery_number_plus'\
value='delivery_nums[num]'\
placeholder='ex(1524587....)' required/>\
<a href='#' class='remove_field btn btn-sm btn-danger'>\
Remove</a></div>";
$(wrapper).append(input); //add input box
}
我想使value = delivery_nums [num]在循环中打印每个项目的值,它会激活我的数字。
答案 0 :(得分:0)
You've got to break out of the script to use variables in the middle of a string like that.
input += "<input type='text' pattern='[0-9]+'\
class='form-control delivery_number_plus'\
value='"+delivery_nums[num]+"'\
placeholder='ex(1524587....)' required/>\
<a href='#' class='remove_field btn btn-sm btn-danger'>\
Remove</a></div>";
答案 1 :(得分:0)
You need to speared the string and variable
var delivery_nums = ($("#delivery_num").val()).split(",");
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
for (var num =0 ; num < delivery_nums.length ; num++ ) {
var input = '<div class="delivery-num-input">';
input += "<input type='text' pattern='[0-9]+'\
class='form-control delivery_number_plus'\
value='"+delivery_nums[num]+"' placeholder='ex(1524587....)' required/>\
<a href='#' class='remove_field btn btn-sm btn-danger'>\
Remove</a></div>";
$(wrapper).append(input); //add input box
}