Javascript最简单的把html字符串编码的方法 var str = '<div id="keleyi">http://www.baidu.com</div>'; console.log(new Option(str).innerHTML);