我正在使用羽毛图标和超棒的字体。我正在使用ajax和innerHTML生成一个dropdown元素。我的问题是我可以生成下拉菜单,但图标未显示。 innerHTML函数是否会干扰图标的初始化?如果可以,我可以使用哪些替代方法?
这是我的示例代码:
HTML代码:
<div class="col-lg-12 btn-grp-hidden" id="btn-grp"></div>
JavaScript代码:
$.ajax({
url: 'generate-loan-application-btn-grp.php',
method: 'POST',
dataType: 'TEXT',
data: {clientid : clientid, name : name, status : status, applno : applno, effectiveyield : effectiveyield, term : term, repaymentamt : repaymentamt, amtfinanced : amtfinanced, frequency : frequency, firstname : firstname, lastname : lastname, middlename : middlename},
success: function(response) {
document.getElementById("btn-grp").innerHTML = response;
}
});
PHP代码:
$response = '<div class="btn-group dropdown dropdown-triangle">
<button class="btn btn-brand btn-long dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="text">Right-aligned menu</span>
<span class="icon"><span data-feather="chevron-down" class="rui-icon rui-icon-stroke-1_5"></span></span>
</button>
<ul class="dropdown-menu dropdown-menu-right nav">
<li><a class="nav-link" href="#"><span data-feather="plus-circle" class="rui-icon rui-icon-stroke-1_5"></span><span>Action</span><span class="rui-nav-circle"></span></a></li>
<li><a class="nav-link" href="#"><span data-feather="x-circle" class="rui-icon rui-icon-stroke-1_5"></span><span>Another action</span><span class="rui-nav-circle"></span></a></li>
<li><a class="nav-link" href="#"><span data-feather="check-circle" class="rui-icon rui-icon-stroke-1_5"></span><span>Something else here</span><span class="rui-nav-circle"></span></a></li>
</ul>
</div>';
echo $response;
答案 0 :(得分:0)
您能在html内找到羽毛图标标签吗?
如果是,则将feather.replace()
放在
$(document).ready(function() {
feather.replace()
})
$(document).ready(function() {
let response = `<div class="btn-group dropdown dropdown-triangle">
<button class="btn btn-brand btn-long dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="text">Right-aligned menu</span>
<span class="icon"><span data-feather="chevron-down" class="rui-icon rui-icon-stroke-1_5"></span></span>
</button>
<ul class="dropdown-menu dropdown-menu-right nav">
<li><a class="nav-link" href="#"><span data-feather="plus-circle" class="rui-icon rui-icon-stroke-1_5"></span><span>Action</span><span class="rui-nav-circle"></span></a></li>
<li><a class="nav-link" href="#"><span data-feather="x-circle" class="rui-icon rui-icon-stroke-1_5"></span><span>Another action</span><span class="rui-nav-circle"></span></a></li>
<li><a class="nav-link" href="#"><span data-feather="check-circle" class="rui-icon rui-icon-stroke-1_5"></span><span>Something else here</span><span class="rui-nav-circle"></span></a></li>
</ul>
</div>`;
console.log(response);
document.getElementById("btn-grp").innerHTML = response;
feather.replace()
})
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<div class="col-lg-12 btn-grp-hidden" id="btn-grp"></div>