我想使用 jquery 在 php 页面中制作动态选择框,但是当我运行代码时它给了我两个错误 SyntaxError: 参数列表后缺少 ),firebug 在线显示此错误
jQuery.post("<? include(FORMKEY."/form_add_events.php"); ?>",function(data){
第二个错误是当我单击“添加事件”按钮时,它给出错误 ReferenceError: addRow 未定义,我如何删除这两个错误并在按钮单击时创建动态选择框,这是我的代码:
<script type="text/javascript">
jQuery.noConflict();
function addRow(btn) {
jQuery.post("<? include(FORMKEY."/form_add_events.php"); ?>",function(data){
$(btn).closest('table').append(data);
});
}
</script>
这是我的 form_add_events.php 代码:
<?php
$strQuery1="SELECT event_id,event_name from events";
$result1 = $GLOBALS ['mysqli']->query ($strQuery1) or die ($GLOBALS ['mysqli']->error . __LINE__);
echo '<tr><td><select>';
while($ors1 = $result1->fetch_assoc()) {
echo '<option value="'.$ors1['event_id'].'">'.$ors1['event_name'].'</option>';
}
echo '</select></td></td>';
?>
这是我的 html 代码:
<table>
<tr>
<td>
<button type="button" value="Add" onclick="addRow(this)">Add Events</button>
</td>
</tr>
</table>
最佳答案
我认为你的引用在这一行中是错误的。尝试在 PHP 字符串中使用单引号,这样它们就不会与 javasacript 的双引号冲突。另外,最佳实践是您使用
jQuery.post("<? include(FORMKEY.'/form_add_events.php'); ?>",function(data){
关于javascript - 如何消除jquery错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21480915/