Onclick content processing method append method to add jQuery can not pass parameters of the problem

The thinking of passing parameters onclick, then by clicking on the pop-up parameters. Not only to find

Directly on the code

$.each(s,function (key,value){
    var text="";
    for(i=0;i<value.LEVELS-1;i++){
         text+="&emsp;&emsp;"
    }
    $("#showDepar").append("<p onclick='test("+value.NAME+")'>"+text+value.NAME+"<br/></p>");
})

After this discovery did not use onclick

This allows the rear into the following method using the onclick

$.each(s,function (key,value){
    var text="";
    for(i=0;i<value.LEVELS-1;i++){
        text+="&emsp;&emsp;"
    }
     $("#showDepar").append("<p onclick='test(\""+value.NAME+"\")'>"+text+value.NAME+"<br/></p>");
})

With the escape character processing parameters, you can pass parameters of normal.

 

Reference: https: //blog.csdn.net/weixin_43187334/article/details/86506091 

Guess you like

Origin www.cnblogs.com/masha2017/p/11237903.html