function strToBase64() { var str = "https://www.baidu.com/"; var val = ""; for (var i = 0; i < str.length; i++) { if (val == "") val = str.charCodeAt(i).toString(16); else val += "," + str.charCodeAt(i).toString(16); } console.log(val) return val; }