javascript – 欧元字符的HTML转义没有在textarea中解释?
作者:互联网
它显示了& euro;而不是textarea中的€(货币符号).有谁知道为什么会出错?
<?php
$currency = "€"; //using php with other data from database
echo "<script>
$('#share_button').click(function(e){
// pass the currency to javascript and put in textarea shared with other on clicks
$('#snsdescp').val(`".$currency."`);
});</script>";
?>
//shared textarea
<textarea class="form-control" name="message" id="snsdescp"></textarea>
解决方法:
val()方法不进行编码/解码,因为hack可以使用html()函数进行编码,然后剥离文本:
$('#share_button').click(function(e){
$('#snsdescp').val($("<div>").html("€").text());
});
Here is a working jsFiddle为您的textarea.
标签:jquery,javascript,euro 来源: https://codeday.me/bug/20190627/1309154.html