使用jQuery与php追加表格

嗨,我试图追加表格中的每一个表格。但是我在控制台中显示错误消息:"Uncaught SyntaxError: missing) after argument list"。当我点击按钮添加行时,它会一直指引我到php脚本。我试图修复它,但无论如何不好意思,因为糟糕的英语,这里是代码。使用jQuery与php追加表格

$('#more_row').append('<tr id="row'+i+'"><td><?php echo "<select name='alpha_num[]' class='form-control' id='item'>"; echo"<option value=''selected disabled>Select Material</option>";while($row = mysqli_fetch_row($result1)){echo"<option value=$row[0]>$row[1]$row[0]</option>";}echo"</select>";?></td><td><input type="text" name="qty[]" class="form-control" id="quantity" placeholder="Qty"></td><td><input type="text" name="uom[]" class="form-control" id="um" placeholder="UOM"></td><td><select name="status[]" class="form-control" id="stat"><option value="approved">approved</option><option value="return">return</option></select></td><td><button id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  

});

$(document).on('click', '.btn_remove', function(){

var button_id = $(this).attr("id");

$('#row'+button_id+'').remove();

});

<div class="panel-body">  

<form method="post" action="material_receive_report_process.php">

<div class="row">

<div class="col">

<label for="dr">PO.NO</label>

<input type="text" name="dr_no" class="form-control" id="dr">

</div>

<div class="col">

<label for="dr">DR.NO</label>

<input type="text" name="dr_no" class="form-control" id="dr">

</div>

<div class="col">

<label for="date">Date</label>

<input type="text" name="date" class="form-control" id="date">

</div>

</div>

<table id="more_row">

<tr>

<td>

<?php echo "<select name='alpha_num[]' class='form-control' id='item'>";

echo"<option value=''selected disabled>Select Material</option>";

while($row = mysqli_fetch_row($result1)){

echo"<option value=$row[0]>$row[1]$row[0]</option>";

}

echo"</select>";

?>

</td>

<td>

<input type="text" name="qty[]" class="form-control" id="quantity" placeholder="Qty">

</td>

<td>

<input type="text" name="uom[]" class="form-control" id="um" placeholder="UOM">

</td>

<td>

<select name="status[]" class="form-control" id="stat">

<option value="approved">approved</option>

<option value="return">return</option>

</select>

</td>

<td><button id="add1" class="btn btn-info">Add</button></td>

</tr>

</table>

<br>

<p>Condition:

<input type="checkbox" name="condition[]" value="damage_visible">Damage visible

<input type="checkbox" name="condition[]" value="good_condition">Good conditon

<input type="checkbox" name="condition[]" value="full_qty">Full qty

<input type="checkbox" name="condition[]" value="partial_qty">Partial qty</p>

<div class="form-group">

<label for="supp">Supplier</label>

<input type="text" name="supplier" class="form-control" id="supp">

</div>

<div class="form-group">

<label for="remark">Remarks</label>

<textarea name="remark" class="form-control" id="remark"></textarea></p>

<input type="submit" name="save" class="btn btn-success" value="Save">

</div>

</form>

<br><br>

</div>

</div>

回答:

'添加行' 按钮提交表单,因为the default value for the type attribute of button elements is "submit"。我的猜测是,语法错误是由于PHP在JavaScript中倾倒的单引号,双引号和换行符的混乱造成的。查看浏览器生成的代码。这就是需要正确形成的东西。

回答:

该错误很可能是由于Php和JavaScript字符串之间的冲突。考虑转义,即\'和使用不同的两个JavaScript使用双引号“,而Php使用单引号'

以上是 使用jQuery与php追加表格 的全部内容, 来源链接: utcz.com/qa/260078.html

回到顶部