jquery 解码 html 实体 µ
jquery decode html entity µ
我发现使用 jquery 和 html 实体 ,html 实体有问题,而不是 解码我猜是自动的。
我研究了很多并尝试了一些 jquery html 实体解码选项,但我无法解决这个问题。任何输入将不胜感激!
使用 jquery 库 3.1.1 btw。
最初拆分并重组为新元素的脚本运行正常。它改变了这个:
<ul class="productList">
<li class="product">
<p class="summary_description">
[[25µg, ABP-NAB-BFGFAB]]
</p>
</li>
</ul>
输出到这里:
<ul class="productList">
<li class="product">
<p class="summary_description">
<div class="prodosku">ABP-NAB-BFGFAB</div>
<div class="prodoweight">25µg</div>
</p>
</li>
</ul>
and displays it as 25& micro; (w/o space of course) but as you can see, the html entity µ ; doesn't convert / decode to the µ symbol.
$( document ).ready(function() {
if( $(".categoryPage").length > 0 ) {
$("#product-listing-container .productList li").each( function() {
var content = $(this).val(".summary_description").html();
content = content.substr( content.indexOf("[["), content.indexOf("]]"));
var weight = '<div class="prodoweight">';
var sku = '<div class="prodosku">';
weight += content.substr( content.indexOf("[[") + 2, content.indexOf(",") - 2);
weight += "</div>";
sku += content.substr( content.indexOf(",") + 1, content.indexOf("]]") - content.indexOf(",") - 1);
sku += "</div>";
$(this).find(".summary_description").html(sku+weight);
});
} });
Is there a way to make sure the µ gets decoded to the µ symbol ???
我一直在考虑类似这样的事情,以确保每个包含 .prodoweight 的 li 都发生变化,但无法使其正常工作。
if( $(".productList li").length > 0 ) {
var decoded = $(".prodoweight").html().text();
$(".prodoweight").html(decoded);
}
或尝试使用 unicode???
if( $(".productList li").length > 0 ) {
var txt = $(".prodoweight").html();
txt = txt.replace("\µ\;", /\[\[([\w\s,\-\u00B5.&;])+\]\]/g);
$(".prodoweight").html(txt);
}
或者也许在初始脚本中有更好的方法来做到这一点???非常感谢。
换行
var content = $(this).val(".summary_description").html();
对此:
var content = $(this).val(".summary_description").text();
它就像一个魅力。
我发现使用 jquery 和 html 实体 ,html 实体有问题,而不是 解码我猜是自动的。
我研究了很多并尝试了一些 jquery html 实体解码选项,但我无法解决这个问题。任何输入将不胜感激!
使用 jquery 库 3.1.1 btw。
最初拆分并重组为新元素的脚本运行正常。它改变了这个:
<ul class="productList">
<li class="product">
<p class="summary_description">
[[25µg, ABP-NAB-BFGFAB]]
</p>
</li>
</ul>
输出到这里:
<ul class="productList">
<li class="product">
<p class="summary_description">
<div class="prodosku">ABP-NAB-BFGFAB</div>
<div class="prodoweight">25µg</div>
</p>
</li>
</ul>
and displays it as 25& micro; (w/o space of course) but as you can see, the html entity µ ; doesn't convert / decode to the µ symbol.
$( document ).ready(function() {
if( $(".categoryPage").length > 0 ) {
$("#product-listing-container .productList li").each( function() {
var content = $(this).val(".summary_description").html();
content = content.substr( content.indexOf("[["), content.indexOf("]]"));
var weight = '<div class="prodoweight">';
var sku = '<div class="prodosku">';
weight += content.substr( content.indexOf("[[") + 2, content.indexOf(",") - 2);
weight += "</div>";
sku += content.substr( content.indexOf(",") + 1, content.indexOf("]]") - content.indexOf(",") - 1);
sku += "</div>";
$(this).find(".summary_description").html(sku+weight);
});
} });
Is there a way to make sure the µ gets decoded to the µ symbol ???
我一直在考虑类似这样的事情,以确保每个包含 .prodoweight 的 li 都发生变化,但无法使其正常工作。
if( $(".productList li").length > 0 ) {
var decoded = $(".prodoweight").html().text();
$(".prodoweight").html(decoded);
}
或尝试使用 unicode???
if( $(".productList li").length > 0 ) {
var txt = $(".prodoweight").html();
txt = txt.replace("\µ\;", /\[\[([\w\s,\-\u00B5.&;])+\]\]/g);
$(".prodoweight").html(txt);
}
或者也许在初始脚本中有更好的方法来做到这一点???非常感谢。
换行
var content = $(this).val(".summary_description").html();
对此:
var content = $(this).val(".summary_description").text();
它就像一个魅力。