javascript - 使用 javascript 函数将一个 unicode 转换为另一个
问题描述
目标:单击时将箭头更改为向下。
我尝试在 Javascript 中使用不同的 unicode 来更改它,但即使通过“\”转义,我也只能得到基本字符串......
小失落。希望这是一个简单的问题。
$('.col-exp').on('click', function() {
let th = $(this);
th.children('span').text('***Change to down arrow***');
th.next('section').slideToggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h2 class="col-exp">Employment<span>⯆</span></h2>
<section id="employment">
<table>
<tr>
<td>FakeSystems Inc</td>
<td>Master Developer</td>
<td>2000-2010</td>
<td>Managed API routing by coordinating with foo and assessing the accuracy of returned data from 3rd party partners</td>
</tr>
<tr>
<td>WorseSystems Inc</td>
<td>Lesser Developer</td>
<td>1990-2000</td>
<td>Made sites with Geocities and Angelfire that included tons of <code>blink</code> tags and gifs to make me look awesome</td>
</tr>
</table>
</section>
<h2 class="col-exp">Education<span>⯆</span></h2>
<section id="education">
<table>
<tr>
<td>Fake Institute of Fortitude</td>
<td>1986-1990</td>
</tr>
</table>
</section>
</div>
</div>
解决方案
您需要使用.html
,因为它是 HTML 实体之一。
使用.text
,它将被视为纯文本,不会被解析为 HTML。
$('.col-exp').on('click', function(){
let th = $(this);
th.children('span').html('⯅');
th.next('section').slideToggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h2 class="col-exp">Employment<span>⯆</span></h2>
<section id="employment">
<table>
<tr>
<td>FakeSystems Inc</td>
<td>Master Developer</td>
<td>2000-2010</td>
<td>Managed API routing by coordinating with foo and assessing the accuracy of returned data from 3rd party partners</td>
</tr>
<tr>
<td>WorseSystems Inc</td>
<td>Lesser Developer</td>
<td>1990-2000</td>
<td>Made sites with Geocities and Angelfire that included tons of <code>blink</code> tags and gifs to make me look awesome</td>
</tr>
</table>
</section>
<h2 class="col-exp">Education<span>⯆</span></h2>
<section id="education">
<table>
<tr>
<td>Fake Institute of Fortitude</td>
<td>1986-1990</td>
</tr>
</table>
</section>
推荐阅读
- kubernetes - 如何阻止 CronJob 重新创建失败的作业?
- java - 如何在java中将空字符串反序列化为空值?
- c# - 在 Unity3d 中使用 TangibleEngine 时,如何避免 Tangibles 在多点触控屏幕中使用的接触点?
- angular - 在 ReactiveForm 中过滤复选框列表会导致呈现错误
- node.js - NodeJS mongoose 查询和承诺
- python - 根据列表中的值生成格式字符串
- c - 5.2 循环二进制如何计算二进制值
- mysql - 我有 3 个表,它们之间有多对多的关系,现在如何在 laravel 中使用 mysql 获取数据
- c# - 从 GUI 执行时进程过早结束,通过控制台测试应用程序执行时不会
- python-3.x - 使用 Numpy 改进 While 循环