在javascript按钮中分配html实体代码不起作用 [英] assigning html entity code in javascript button not working
本文介绍了在javascript按钮中分配html实体代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在javascript中创建一个按钮,并将HTML实体代码⛨
分配给它.这是向下箭头的HTML实体代码.整个代码不会显示向下箭头,而是直接显示在按钮中.
I am trying to create a button in javascript and assigning HTML entity code ⛨
to it. This is the HTML entity code of down arrow. Instead of showing the down arrow, the entire code is displayed in the button as is.
下面是我如何实现这一目标
Below is how i am trying to achieve it
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="text/javascript">
var btn = document.createElement("input");
btn.setAttribute('type','button');
btn.setAttribute('value','▼');
document.body.appendChild(btn);
</script>
</body>
</html>
下面是我的代码的输出
我希望该按钮应该显示向下箭头,但是由于某种原因它没有显示.
I expect that the button should display down arrow but for some reason it is not showing.
推荐答案
您应使用 innerHTML
而不是setAttribute:
You should use innerHTML
instead of setAttribute:
var btn = document.createElement("input");
btn.setAttribute('type','button');
btn.innerHTML = '⛨';
document.body.appendChild(btn);
这篇关于在javascript按钮中分配html实体代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文