使用Javascript打印HTML:未定义错误
Printing HTML with Javascript : is not defined error
我正在开发一个使用HTML、PHP和Javascript JQuery的网站我有一个html格式的数据表,我在其中打印数据库中的结果。每一行都有一个删除按钮,我在其中调用一个javascript函数。
现在我想使用javascript在该表中插入一行,这很有效,但问题是如何正确打印删除按钮的函数。
onclick函数需要解析元素和品牌名称(关于汽车)
代码将解释更多:
数据表:
<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();
这添加了行,但当我单击按钮时,我会得到错误"Uncaught ReferenceError:宝马没有定义"宝马是品牌的名称
有什么想法吗?
试试这个:
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();
相关文章:
- chrome.storage.sync未定义错误
- 对象为null或IE9中存在未定义错误
- 已定义变量出现未定义错误
- 'define' 在 RequireJS 和 Webapp Yo 生成器上未定义错误
- onreadystatechange未定义错误
- 在CoffeeScript文件上运行Jasmine测试时,对象未定义错误
- 如何修复JSlint报告的“foo未定义”错误
- 无法仅在活动服务器上读取未定义错误的属性“top”
- 主干无法读取属性'属性'主干视图中的未定义错误
- 如何克服javascript中的未定义错误
- require未定义错误
- 单击链接时出现函数未定义错误
- 函数为未定义错误
- 主干未定义错误
- 使用Javascript打印HTML:未定义错误
- 避免“无法读取”属性'获取'的未定义错误
- 未捕获类型错误的coffescription:无法读取属性'offsetWidth'的未定义错误
- ajax上get函数内部的未定义错误
- Javascript变量未定义错误
- AngularJS指令作用域未解析(“属性名称未定义”错误)