无效或意外令牌是Java脚本中的变量

问题描述 投票:0回答:1

我在按钮上附加一个选择框,然后从查询中获取选择框的值,但是一个文件的名称没有显示控制台中的错误的名称无效或意外的标记变量附加代码为

$(document).ready(function () {
$("#btnAdd").click(function() { 
$(".zims").append('<tr> <td><select name="material_id[]" required class="s_box"><option value="">-Select Material-</option><?php foreach ($get_mat as $row) {  ?><option value="<?php echo $row->id ?>"><?php echo $row->name ?></option> <?php } ?>  </select> </td></tr>');
}); });

$ row-> name有问题!用有效的ID替换名称时的>]

查询是

$this->db->select('*');
$this->db->from('material');
$query = $this->db->get();
return $query->result();

为何说明如何解决此问题?名称在该循环中,加号按钮不起作用,但替换为id则起作用!

$ get_mat

结果是
array(33) { [0]=> object(stdClass)#97 (2) { ["id"]=> string(1) "1" ["name"]=> string(5) " Nail" } [1]=> object(stdClass)#98 (2) { ["id"]=> string(1) "2" ["name"]=> string(6) "Washer" } [2]=> object(stdClass)#99 (2) { ["id"]=> string(1) "3" ["name"]=> string(5) "L bow" } [3]=> object(stdClass)#100 (2) { ["id"]=> string(1) "4" ["name"]=> string(9) "Chemical " } [4]=> object(stdClass)#101 (2) { ["id"]=> string(1) "5" ["name"]=> string(19) "Polishing material " } [5]=> object(stdClass)#102 (2) { ["id"]=> string(1) "6" ["name"]=> string(6) "Paints" } [6]=> object(stdClass)#103 (2) { ["id"]=> string(1) "7" ["name"]=> string(3) "Bit" } [7]=> object(stdClass)#104 (2) { ["id"]=> string(1) "8" ["name"]=> string(6) "Cement" } [8]=> object(stdClass)#105 (2) { ["id"]=> string(1) "9" ["name"]=> string(7) "M Sand " } [9]=> object(stdClass)#106 (2) { ["id"]=> string(2) "10" ["name"]=> string(7) "P Sand " } [10]=> object(stdClass)#107 (2) { ["id"]=> string(2) "11" ["name"]=> string(11) "20 mm metal" } [11]=> object(stdClass)#108 (2) { ["id"]=> string(2) "12" ["name"]=> string(5) "Chips" } [12]=> object(stdClass)#109 (2) { ["id"]=> string(2) "13" ["name"]=> string(7) "Q dust " } [13]=> object(stdClass)#110 (2) { ["id"]=> string(2) "14" ["name"]=> string(13) "Baniyan waste" } [14]=> object(stdClass)#111 (2) { ["id"]=> string(2) "15" ["name"]=> string(13) "Cutting blade" } [15]=> object(stdClass)#112 (2) { ["id"]=> string(2) "16" ["name"]=> string(15) "Electrical item" } [16]=> object(stdClass)#113 (2) { ["id"]=> string(2) "17" ["name"]=> string(14) "Plumbing item " } [17]=> object(stdClass)#114 (2) { ["id"]=> string(2) "18" ["name"]=> string(15) "Carpentry item " } [18]=> object(stdClass)#115 (2) { ["id"]=> string(2) "19" ["name"]=> string(14) "Painting item " } [19]=> object(stdClass)#116 (2) { ["id"]=> string(2) "20" ["name"]=> string(4) "Rope" } [20]=> object(stdClass)#117 (2) { ["id"]=> string(2) "22" ["name"]=> string(11) "Level hose " } [21]=> object(stdClass)#118 (2) { ["id"]=> string(2) "23" ["name"]=> string(7) "Fissure" } [22]=> object(stdClass)#119 (2) { ["id"]=> string(2) "24" ["name"]=> string(11) "40 mm metal" } [23]=> object(stdClass)#120 (2) { ["id"]=> string(2) "25" ["name"]=> string(13) "Hardware Item" } [24]=> object(stdClass)#121 (2) { ["id"]=> string(2) "26" ["name"]=> string(6) "Bricks" } [25]=> object(stdClass)#122 (2) { ["id"]=> string(2) "27" ["name"]=> string(6) "Rubble" } [26]=> object(stdClass)#123 (2) { ["id"]=> string(2) "28" ["name"]=> string(6) "Steel " } [27]=> object(stdClass)#124 (2) { ["id"]=> string(2) "29" ["name"]=> string(14) "Polishing item" } [28]=> object(stdClass)#125 (2) { ["id"]=> string(2) "30" ["name"]=> string(11) "silicon gun" } [29]=> object(stdClass)#126 (2) { ["id"]=> string(2) "31" ["name"]=> string(13) "Granite Blade" } [30]=> object(stdClass)#127 (2) { ["id"]=> string(2) "32" ["name"]=> string(5) "Blade" } [31]=> object(stdClass)#128 (2) { ["id"]=> string(2) "33" ["name"]=> string(5) "Water" } [32]=> object(stdClass)#129 (2) { ["id"]=> string(2) "34" ["name"]=> string(11) "Glass Point" } }

我在按钮上附加一个选择框,然后从查询中获取选择框的值,但是一个文件的名称不显示控制台中的错误。无效或意外的标记,变量...

javascript codeigniter append
1个回答
0
投票
请像这样更改附加代码
© www.soinside.com 2019 - 2024. All rights reserved.