<?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()
方法不会设置 HTML,因此"€"
不会被视为 HTML 实体,而只是被视为普通字符串。您可以使用类似.val($("<div>").html("€").text())
的“hack”来获取实际的欧元字符。 - nnnnnnhtml()
代替val()
。就像这样:$('#snsdescp').html('€');
- phobia82€
。确保文件保存为 UTF-8,以 UTF-8 提供,并设置 HTML meta 字符集为 UTF-8。 - user663031