使用jQuery在.click()上插入字符实体

使用jQuery在.click()上插入字符实体,jquery,html,insert,entity,character,Jquery,Html,Insert,Entity,Character,我想插入角色实体✓ 单击href后列表项末尾的(✓;): <a href="" id="answer1">Click here to answer</a> <ul> <li>Answer 1</li> </ul> $("#answer1").click(function(){ // Add &#10003; to the end of the list item, such as: "<li&g

我想插入角色实体✓ 单击href后列表项末尾的(
✓;
):

<a href="" id="answer1">Click here to answer</a>

<ul>
<li>Answer 1</li>
</ul>

$("#answer1").click(function(){
// Add &#10003; to the end of the list item, such as: "<li>Answer 1 &#10003;</li>"
});

  • 答复1
$(“#答案1”)。单击(函数(){ //将✓;添加到列表项的末尾,例如:“
  • 答案1✓;
  • ” });
    非常感谢您的帮助!
    谢谢

    您可以使用以下代码

    $("#answer1").click(function(){
       $(this).html() += $(this).html() + '&#10003'; // just format the Html anyway you want
    });
    
    编辑

    我看错了你的问题

    为了你的保险单。。。有点像

    <ul>
       <li>Answer 1</li>
       <li>Answer 2</li>
       <li>Answer 3</li>
    </ul>
    

    我不知道您有多少li元素,但是对于您所展示的这个html

    $("#answer1").click(function(){
        $('ul li').append('&#10003;');
    });
    

    但这将附加“✓;”给所有李的。。哦,好吧,这是可以接受的。我只为他的html写了这篇文章(如问题中所示)。可能他只有一个ul和li。
    $("a.answers").click(function(){
       // get the answer index
       var i = $(this).attr("data-answer");
    
       var answer = $("ul > li:eq(" + i + ")");
       answer.html( answer.html() + '&#10003' );
     });
    
    $("#answer1").click(function(){
        $('ul li').append('&#10003;');
    });