Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选择选项中的Html文本不是';t渲染_Jquery_Laravel_Jquery Select2 - Fatal编程技术网

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 &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b; // I'll "walk" the <b>dog</b> now
?>