如何在javascript中设置单引号

LOK*_*ESH 5 javascript php ajax jquery

我想用单引号设置javascript变量.怎么可能.我将值作为参数传递给我的函数.我正在使用此值来检索复选框的值.所以我的问题是,如果我提醒值,那么它会给我'用户'而不是'sanjay'这里'sanjay'是我的价值,这是我传递给参数.这将用于检索复选框document.getElementById的值.

function single(user){

                var abc = '\' user \'';
                alert(abc);
                return false;
                var chksingle = document.getElementById(abc).checked;
                alert(chksingle);
                return false;
                if (userlist() === false)
                {
                    return false;
                }
                else
                {           
                        document.tallyexport.method = "post";
                        document.tallyexport.action = "checksingle.php";
                        document.tallyexport.submit();          
                }
            }
Run Code Online (Sandbox Code Playgroud)

Ima*_*n K 7

使用字符串连接.你现在这样做的方式是user作为实际字符串的一部分,而不是使用变量.

var abc = "' " + user + " '"
Run Code Online (Sandbox Code Playgroud)