Jquery 选择选项中的Html文本不是';t渲染
我使用Jquery 选择选项中的Html文本不是';t渲染,jquery,laravel,jquery-select2,Jquery,Laravel,Jquery Select2,我使用select2在select的选项中呈现html标记,如下所示: $('#select2colors').append($('<option>', { value: color, text: `<i class="fas fa-square" style="color: ${color}; width:100%;"></i>` })); $("#select2colors&quo
select2
在select的选项中呈现html标记,如下所示:
$('#select2colors').append($('<option>', {
value: color,
text: `<i class="fas fa-square" style="color: ${color}; width:100%;"></i>`
}));
$("#select2colors").select2({
escapeMarkup: function(markup) {
return markup;
}
我以为它也能用,但事实并非如此。
正在消失,根本没有被渲染。有人知道我怎样才能做到这一点,使之与以前一样吗
我得到的是,HTML没有呈现:
我在启动时所做的是直接将HTML放入,我必须将HTML转换为纯文本,就像@Mohamed Yousef comment一样。首先我使用了
htmlentities()
,但我需要的是html\u entity\u decode()
,解释如下:
为什么不使用append?第一种方法是用于我的create视图,第二种方法是用于我的edit视图,我在该视图中有数据,这是因为我使用@foreach
,而且我正在处理外部js文件,无法将数据发送到这些文件。当删除错误抑制时会发生什么?这不是宽度=100%代码>宽度:100%代码>内部样式attribute@L.Flor追加时,…
是一个文本。。在第二个代码中,..
i
这是一个html。。所以,试着找到一种将…
转换为字符串/文本的方法,我想一切都会好起来的
<select class="form-control form-control-sm" id="select2colors">
@foreach($colors as $color)
<option value="#{{ $color }}">
{{ htmlentities("<i class='fas fa-square' style='color: #".$color."; width:100%;'></i>") }}
</option>
@endforeach
</select>
$("#select2colors").select2({
escapeMarkup: function(markup) {
return markup;
}
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll "walk" the <b>dog</b> now
echo $b; // I'll "walk" the <b>dog</b> now
?>