我这里有一个函数,可以在单击时在不同的 ASCII 符号(特别是 ⊕ (⊕)
和 &ominus (⊖)
)之间切换。我不明白的是它变成 ⊖
之后它不会变回来。有谁知道为什么吗?
这会生成表格行
"<tr><td>Other</td><td>" + stats.others.length + <span class='displaybutton' style='cursor:pointer;'>⊕</span></td></tr>";
重要的部分是这个<span>
<span class='displaybutton' style='cursor:pointer;'>⊕</span>
这应该在符号之间切换
$('.displaybutton').click(function(){
$('#otherResponseList').toggle();
if($(this).html() == '⊖'){
$(this).html('⊕');
} else {
$(this).html('⊖');
}
});
最佳答案
这两个符号不是 ASCII。它们是 HTML 实体,属于 Unicode 字符集。它们不属于 ASCII 字符集。
比较 HTML 实体的 html 表示可能很棘手。它们可以用实体来表示,但也可以转换为相应的Unicode字符。解决方案是考虑结果,即文本内容。使用 jQuery.text()
和 Unicode 代码点可以轻松操作文本内容到 ominus (0x2296) 和 oplus (0x2295):
$('.displaybutton').click(function(){
$('#otherResponseList').toggle();
$(this).text($(this).text()=='\u2296'?'\u2295':'\u2296');
});
关于javascript - .html() 未注册 ASCII 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42427716/