使用Javascript打印HTML:未定义错误
我正在使用HTML、PHP和Javascript JQuery开发一个网站 我有一个html格式的datatable,在那里我从数据库打印结果。 每行都有一个delete按钮,在这里我调用一个javascript函数 现在我想使用javascript在该表中插入一行,这是可行的,但问题是如何正确打印delete按钮的函数 onclick函数需要解析与汽车相关的元素和品牌名称 该守则将进一步解释: 数据表:使用Javascript打印HTML:未定义错误,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我正在使用HTML、PHP和Javascript JQuery开发一个网站 我有一个html格式的datatable,在那里我从数据库打印结果。 每行都有一个delete按钮,在这里我调用一个javascript函数 现在我想使用javascript在该表中插入一行,这是可行的,但问题是如何正确打印delete按钮的函数 onclick函数需要解析与汽车相关的元素和品牌名称 该守则将进一步解释: 数据表: <table class="table table-striped table-bo
<table class="table table-striped table-bordered table-hover roles-table" id="makes">
<thead>
<tr>
<th>Merk</th>
<th>Verwijderen</th>
</tr>
</thead>
<tbody>
<?php $result = $userProfile->getSubBrands($companyId);
foreach($result as $subBrand):
?>
<tr class="role-row" >
<td>
<?php echo htmlentities($subBrand['brand_name']); ?>
</td>
<td>
<button type="button" class="btn btn-danger" onclick="profile.deleteSubs(this,'<?php echo htmlentities($subBrand['brand_name']); ?>');">
<i class="fa fa-trash-o"></i> Verwijderen </button>
</td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
如何使用jquery添加行res来自JSON结果解析:
t.row.add([
res.brandName,
'<button type="button" class="btn btn-danger" onclick="profile.deleteSubs(this,'+res.brandName+');"><i class="fa fa-trash-o"></i> Verwijderen</button>'
]).draw();
这会添加行,但当我单击按钮时,会出现错误
未捕获参考错误:未定义BMW BMW是品牌名称
有什么想法吗?试试这个:
t.row.add([
res.brandName,
'<button type="button" class="btn btn-danger" onclick="profile.deleteSubs(this,\''+res.brandName+'\');"><i class="fa fa-trash-o"></i> Verwijderen</button>'
]).draw();
你需要用引号把BMW括起来。什么是deleteSubs?deleteSubs只是一个调用ajax函数的函数,没有什么特别的,只是将元素和品牌名称解析成AjaxSubs就行了!谢谢但是现在行没有消失,元素没有正确解析?这就是我隐藏行的方式:$element.parents.role-row.fadeOutslow,函数{$this.remove;};