Bootstrap Table中图片与链接无法渲染仅显示代码,如何解决?
解决Bootstrap Table中HTML内容无法渲染的问题
Bootstrap Table默认会转义所有单元格内容(出于安全考虑),这就是你的图片、链接显示原始HTML代码的原因。要让HTML内容正常渲染,只需给需要解析HTML的列添加data-escape="false"属性即可。
修改步骤
找到表格表头中对应图片和链接的<th>标签,分别添加data-escape="false":
- 图片列(对应
data-field="examen") - 链接列(对应
data-field="note")
修改后的完整表格代码
<table id="table" data-toggle="table" data-search="true" data-filter-control="true" data-show-export="true" data-show-refresh="true" data-show-toggle="true" data-pagination="true" data-toolbar="#toolbar" class="table-responsive"> <thead> <tr> <th data-field="state" data-checkbox="true"></th> <th data-field="prenom" data-filter-control="input" data-sortable="true">Title</th> <th data-field="date" data-filter-control="select" data-sortable="true">Price</th> <!-- 图片列添加data-escape="false" --> <th data-field="examen" data-filter-control="select" data-sortable="true" data-escape="false">Image</th> <!-- 链接列添加data-escape="false" --> <th data-field="note" data-sortable="true" data-escape="false">Link</th> </tr> </thead> <tbody> <tr> <td class="bs-checkbox "><input data-index="0" name="btSelectItem" type="checkbox"></td> <td>Maths Tution</td> <td>$20</td> <td><img src="https://i.imgur.com/0GoaYKd.jpg" height="100" width="100"></td> <td><a href="https://monsoonmalabar.com/sonyshop/other/product-13/">Go</a></td> </tr> <tr> <td class="bs-checkbox "><input data-index="1" name="btSelectItem" type="checkbox"></td> <td>Milk</td> <td>$5</td> <td><img src="https://i.imgur.com/2ZOroMI.jpg" height="100" width="100"></td> <td><a href="https://monsoonmalabar.com/sonyshop/test_category_2/product-6/">Go</a></td> </tr> </tbody> </table>
说明
data-escape="false"会告诉Bootstrap Table不要转义该列的内容,直接解析渲染其中的HTML代码,这样图片和链接就能正常显示了。
内容的提问来源于stack exchange,提问作者J C
相关产品推荐
相关产品推荐

