Passing a parameter to function with single quote

前端 未结 5 1094
抹茶落季
抹茶落季 2021-01-07 19:08

How do I pass a parameter to a javascript function with \' included

var name =\"Lauren O\'Donald\";

var htmlAnch=\'

        
5条回答
  •  萌比男神i
    2021-01-07 19:55

    Write your own function to return a escaped string. Demo

    Pass your string as argument to this function and you will get escaped string. You can also add more characters to blocklist if you want to escape some more characters

    function remove_quotes(values1)
    {
            var values = values1.toString();
            var str = "";
            var blockList = ['"','\'','\\']; // This is the list of key words to be escaped
            var flag = 0;
            for(var i = 0;i

提交回复
热议问题