如何在 javascript 中使用 unicode 字符
how to use unicode character in javascript
对于查看和隐藏一些评论的js点击功能,我使用这个unicode
▼
和 ▲
(向上箭头和向下箭头)
$('.toggle-<?php echo $comment_id; ?>').click(function(){
$(this).text($(this).text() == 'Hide replies ▲' ? 'View replies ▼' : 'Hide replies ▲');
但它确实向我显示了代码而不是箭头。
那么我需要如何使用上面脚本中的代码呢?
语法 &#<num>;
是 html,因此需要这样输入,使用 $(...).html('▼ ...')
而不是 $(...).text('▼ ...')
。
以下应该有效:
$(this).html($(this).text().substr(0,4) == 'Hide' ? 'View replies ▼' : 'Hide replies ▲');
对于查看和隐藏一些评论的js点击功能,我使用这个unicode
▼
和 ▲
(向上箭头和向下箭头)
$('.toggle-<?php echo $comment_id; ?>').click(function(){
$(this).text($(this).text() == 'Hide replies ▲' ? 'View replies ▼' : 'Hide replies ▲');
但它确实向我显示了代码而不是箭头。
那么我需要如何使用上面脚本中的代码呢?
语法 &#<num>;
是 html,因此需要这样输入,使用 $(...).html('▼ ...')
而不是 $(...).text('▼ ...')
。
以下应该有效:
$(this).html($(this).text().substr(0,4) == 'Hide' ? 'View replies ▼' : 'Hide replies ▲');