在工作中遇到的问题:
<input type="button" value="Embed & Share ⇓" id="share_button"/>
我需要将value值变为 “
Embed & Share ⇑”;
这里需要需要将给value赋值,如果使用之下的代码会出现value == “Embed & Share &uArr ”;
<script>
$("#share_button").click(function(){
$(this).attr("value", "Embed & Share ⇑");
})
</script>
所以需要将html entity编码,之下是解决的方法;
<script>
$("#share_button").click(function(){
$(this).attr("value", "Embed & Share " + $("<div>").html("⇑").text());
})
</script>
在这里需要解释两个概念
text() ---- 返回字符串
text(value) ----返回object,string object