JavaScript 将 my<
转换为>
. 我想提醒它,但我的消息带有编码标记,例如@#&*()}{>?>?
- 如何正常显示它但防止作为 HTML 代码执行?
<span id="ID" onClick="alertIt(this.id);">
<p>Some string with special chars: ~!@#&*()}{>?>?>|{">@#$#^#$</p>
<p>Why when clicked it gives something like this:</p>
<p>'<br>
Some string with special chars: ~!@#&*()}{>?>?>|... and so on
<br>'</p>
</span>
<script type="text/javascript">
function alertIt(ID)
{
var ID = ID;
var content = document.getElementById(ID).innerHTML;
alert(content);
}
</script>