Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
Javascript 文本区域中未解释欧元字符的HTML转义?_Javascript_Jquery_Euro - Fatal编程技术网

Javascript 文本区域中未解释欧元字符的HTML转义?

Javascript 文本区域中未解释欧元字符的HTML转义?,javascript,jquery,euro,Javascript,Jquery,Euro,它显示的是&欧元而不是文本区域中的€(货币符号)。有人知道为什么会出问题吗 <?php $currency = "&euro;"; //using php with other data from database echo "<script> $('#share_button').click(function(e){ // pass the currency to javascript and put in textarea shared w

它显示的是
&欧元而不是文本区域中的€(货币符号)。有人知道为什么会出问题吗

<?php
$currency = "&euro;"; //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()
函数进行编码,然后去除文本:

$('#share_button').click(function(e){
    $('#snsdescp').val($("<div>").html("&euro;").text());
});
$(“#共享按钮”)。单击(功能(e){
$('#snsdescp').val($(“”).html(“&euro;”).text());
});

用于您的文本区域。

您可以通过分配
&欧元来设置它
textarea
元素的
innerHTML
属性:

document.querySelector('#snsdescp').innerHTML = '&euro;';
如果要使用jQuery,只需调用其
.html()
方法:

$('#snsdescp').html('&euro;');

我不明白为什么要存储在php变量中,但也许可以存储在javascript变量中。它可以帮助你

<?php
  $currency = "\u20ac"; //using php with other data from database
?>

 <textarea class="form-control" name="message" id="snsdescp"></textarea> 
  <br/><br/>
  <div id="share_button" >hello</div>//suppose your id is here

 <script>
    var value ="<?php echo $currency;?>"; //store php value in js variable
    $("#share_button").click(function(){

        $("#snsdescp").val(value);

     });
  </script>



您好//假设您的id在这里 var值=”//将php值存储在js变量中 $(“#共享按钮”)。单击(函数(){ $(“#snsdescp”).val(价值); });
您可以对€\u20AC使用Unicode


$('snsdescp').val(“\u20AC”)

方法
.val()
不设置html,因此
“&euro;”
不被视为html实体,只被视为普通字符串。您可以使用诸如
.val($(“”).html(“&euro;”).text())
之类的“hack”来获取实际的欧元字符。因为您将其作为
文本区域
中的值添加,而不是作为将被解析的html添加。可能有帮助,服务器端不需要破解它,使用
html()
而不是
val()
。比如
$('#snsdescp').html('&euro;')只需使用实际的欧元字符
。确保文件保存为UTF-8,用作UTF-8,并且HTML元字符集设置为UTF-8。textarea没有
innerHTML
属性。这一点很好。在这种情况下,Chrome似乎尝试做正确的事情,即使它不受跨平台支持。如果文本包含