我的append
功能存在问题。我试图通过使用数据库中的值来显示选择option
中的图像,但是用户可以通过使用{{1生成选择option
来动态添加更多option
函数 - 但我收到了这个错误;
Uncaught SyntaxError:missing)参数列表...
之后
这是可行的代码;
append
这是<select data-show-subtext="true" class=" selectpicker bs-select form-
control" data-live-search="true" data-size="8" name="city">
<option value=""></option>
<?php foreach($get_drawing as $row): $image=$row->image; ?>
<option data-subtext="<img width='28%' height='90%'' src='<?=base_url("drawing/fabricator/admin_3/".$row->image);?>'>"
value="<?php echo $row->drawing_id; ?>" >
<?php echo $row->drawing_name;?>
</option>
代码:
append
根据我的知识,问题在于这一行,但我不知道如何更正$('#add').click(function(){
j++;
$('#dynamic_field').append('<div id="row'+j+'" class="row" style="margin-bottom:15px;"><hr><div class=col-sm-1 form-group-sm" style="margin-top:25px; margin-bottom:10px;"><button type="button" name="remove" id="'+j+'" class="btn btn-danger btn_remove"> <i class="fa fa-close"></i></button></div><div class="col-sm-2 form-group-sm"> <label class="control-label">Drawing</label> <select data-show-subtext="true" class=" selectpicker bs-select form-control" data-live-search="true" data-size="8" name="city"><option value=""></option><?php foreach($get_drawing as $row): ?><option data-subtext=<img width='28%' height='90%'' src='<?=base_url("drawing/fabricator/admin_3/".$row->image);?>'>" value="<?php echo $row->drawing_id; ?>" ><?php echo $row->drawing_name;?> </option><?php endforeach; ?></select></div><div class="col-sm-1 form-group-sm"><label class="control-label">Type</label><input type="text" placeholder="Bed Front" class="form-control sm" name="type" value="22"/> </div><div class="col-sm-2 form-group-sm"><label class="control-label">Profile Series</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="pf"/> </div><div class="col-sm-2 form-group-sm"><label class="control-label">Location</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="location"/></div><div class="col-sm-1 form-group-sm"><label class="control-label">Width</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="width"/> </div><div class="col-md-1 form-group-sm"><label class="control-label">Height</label> <input type="text" placeholder="Bed Front" class="form-control" value="22" name="height"/> </div> <div class="col-md-1 form-group-sm"><label class="control-label">Quantity</label> <input type="text" placeholder="Bed Front" class="form-control" value="22" name="quantity"/> </div> <div class="col-md-1 form-group-sm"> <label class="control-label">Fixed</label> <input type="text" placeholder="Height" class="form-control" value="" name="fixed_height"/><br><input type="text" placeholder="Height" class="form-control" value="" name="fixed_width"/></div></div>');
$('.selectpicker').selectpicker('render');
});
函数中的代码,因为如果我更改它,它就不起作用。
append
提前致谢。
答案 0 :(得分:0)
$('#add').click(function(){
j++;
$('#dynamic_field').append('<div id="row"'+j+'" class="row" style="margin-bottom:15px;"><hr><div class=col-sm-1 form-group-sm" style="margin-top:25px; margin-bottom:10px;"><button type="button" name="remove" id="'+j+'" class="btn btn-danger btn_remove"> <i class="fa fa-close"></i></button></div><div class="col-sm-2 form-group-sm"> <label class="control-label">Drawing</label> <select data-show-subtext="true" class=" selectpicker bs-select form-control" data-live-search="true" data-size="8" name="city"><option value=""></option><?php foreach($get_drawing as $row): ?><option data-subtext="<img width="28%" height="90%" src="'<?=base_url('drawing/fabricator/admin_3/'.$row->image);?>'">" value="<?php echo $row->drawing_id; ?>" ><?php echo $row->drawing_name;?> </option><?php endforeach; ?></select></div><div class="col-sm-1 form-group-sm"><label class="control-label">Type</label><input type="text" placeholder="Bed Front" class="form-control sm" name="type" value="22"/> </div><div class="col-sm-2 form-group-sm"><label class="control-label">Profile Series</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="pf"/> </div><div class="col-sm-2 form-group-sm"><label class="control-label">Location</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="location"/></div><div class="col-sm-1 form-group-sm"><label class="control-label">Width</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="width"/> </div><div class="col-md-1 form-group-sm"><label class="control-label">Height</label> <input type="text" placeholder="Bed Front" class="form-control" value="22" name="height"/> </div> <div class="col-md-1 form-group-sm"><label class="control-label">Quantity</label> <input type="text" placeholder="Bed Front" class="form-control" value="22" name="quantity"/> </div><div class="col-md-1 form-group-sm"> <label class="control-label">Fixed</label> <input type="text" placeholder="Height" class="form-control" value="" name="fixed_height"/><br><input type="text" placeholder="Height" class="form-control" value="" name="fixed_width"/></div></div>');
$('.selectpicker').selectpicker('render');
});
将您的追加功能替换为此功能。你错误地放置了单引号,这打破了字符串。
答案 1 :(得分:0)
试试这个:
$('#dynamic_field').append('<hr><div class="col-sm-1 form-group-sm" style="margin-top:25px; margin-bottom:10px;"><button type="button" name="remove" id="' + j + '" class="btn btn-danger btn_remove"> <i class="fa fa-close"></i></button></div><div class="col-sm-2 form-group-sm"> <label class="control-label">Drawing</label><select data-show-subtext="true" class="selectpicker bs-select form-control" data-live-search="true" data-size="8" name="city"><option value=""></option><?php foreach ($get_drawing as $row): ?><option data-subtext="<img width="28%" height="90%" src="<?= base_url("drawing/fabricator/admin_3/" . $row->image); ?>">" value="<?php echo $row->drawing_id; ?>"><?php echo $row->drawing_name; ?></option><?php endforeach; ?></select></div><div class="col-sm-1 form-group-sm"><label class="control-label">Type</label><input type="text" placeholder="Bed Front" class="form-control" name="type" value="22"/></div><div class="col-sm-2 form-group-sm"><label class="control-label">Profile Series</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="pf"/></div><div class="col-sm-2 form-group-sm"><label class="control-label">Location</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="location"/></div><div class="col-sm-1 form-group-sm"><label class="control-label">Width</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="width"/></div><div class="col-md-1 form-group-sm"><label class="control-label">Height</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="height"/></div><div class="col-md-1 form-group-sm"><label class="control-label">Quantity</label><input type="text" placeholder="Bed Front" class="form-control" value="22" name="quantity"/></div><div class="col-md-1 form-group-sm"> <label class="control-label">Fixed</label><input type="text" placeholder="Height" class="form-control" value="" name="fixed_height"/><br><input type="text" placeholder="Height" class="form-control" value="" name="fixed_width"/></div></div>');
您的代码极难阅读,可能会将其分成几部分。