简体   繁体   English

如何在 javascript 中使用 unicode 字符

[英]how to use unicode character in javascript

For a js click function to View and Hide some comments, i use this unicode ▼对于 js 点击 function 查看和隐藏一些评论,我使用这个 unicode ▼ and ▲▲ (Arrow up and arrow down) (向上箭头和向下箭头)

$('.toggle-<?php echo $comment_id; ?>').click(function(){
    $(this).text($(this).text() == 'Hide replies &#9650;' ? 'View replies &#9660;' : 'Hide replies &#9650;'); 

But it shows me literally the code instead of the arrow.但它从字面上向我显示了代码而不是箭头。

So how i need to use the code in the script above?那么我需要如何使用上面脚本中的代码呢?

The syntax &#<num>;语法&#<num>; is html, therefore it needs to be entered as such, using $(...).html('&#9660...') instead of $(...).text('&#9660...') .是 html,因此需要这样输入,使用$(...).html('&#9660...')而不是$(...).text('&#9660...') .

The following should work:以下应该有效:

$(this).html($(this).text().substr(0,4) == 'Hide' ? 'View replies &#9660;' : 'Hide replies &#9650;'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM