![](/img/trans.png)
[英]How do I output unescaped HTML with javascript in Laravel Blade?
[英]How to render blade html with javascript execution. (Laravel and Blade)
我需要從報告視圖中獲取內容 html,但某些元素正在通過 javascript 如何填充 div。
在 laravel 我使用 view('report')->render(); 但只返回空的 div:
<div id="report"></div>
渲染器不執行我的 javascript 函數,是否存在一種解決方案?
我需要獲取內容 html,DOM 元素通過 javascript function 完成渲染
JavaScript是客戶端,除非你在瀏覽器中打開它才能執行。 因此,無法使用由 JavaScript 填充的 render() 檢索數據
我使用解決方法。
假設您想使用一行來填充一些“正確”的表。 您可以構建一個假表作為模板。 它會為你提供它的行:
模板.mytamplate.blade.php
<table id="mock_table" class="table w-75 mx-auto " hidden>
<thead>
</thead>
<tbody>
<tr id="tr_id" > {{-- this row --}}
<td ></td>
<td></td>
<td></td>
<td></td>
<td>
<div onclick="" class=" w-50 shadow-lg text-center " id="editButton">
<img src="/images/pencil.svg" class="rounded " style="pointer-events: none;height: 20px; width: 20px">
</div>
</td>
<td>
<div onclick="" class=" w-50 shadow-lg text-center" id="deleteButton">
<img src="/images/trash-can.svg" class="rounded "
style="pointer-events: none;height: 20px; width: 20px">
</div>
</td>
</tr>
</tbody>
現在回到主刀片:
@section('mycontent')
<div id="backg" class="vh-100 w-100 bg-white"> </div>
@include('templates.mytamplate')
....
<script type="text/javascript">
$(function () {
$('#backg').remove()
........
// in your template the table marked as hidden not the row :
let clone_ = $('#mock_table').clone()
let tr_ = clone_.find('#tr_id')
let myHtmlString_= tr_[0].outerHTML
});
....
</script>
@endsection
$('#backg') 在初始化時隱藏表格,模擬內容可能會在某些瀏覽器中立即閃爍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.