How to use variable in string in jQuery

后端 未结 7 2022
陌清茗
陌清茗 2020-12-08 23:28

I want to use a variable in a string. I have tried to do it many times, but it is only getting the variable name.


    

        
7条回答
  •  爱一瞬间的悲伤
    2020-12-08 23:48

    The correct way of doing this is is by taking advantage of jQuery's HTML constructor to perform all the necessary escaping for you:

    $("a").click(function() {
        var id= $(".id").html();
        // create new element
        $('
    ', { class:'new', id: id, text: 'jitend' }).appendTo('.html'); // and append it });

提交回复
热议问题