Javascript最简单的把html字符串编码的方法

var str = '<div >http://www.baidu.com</div>';

console.log(new Option(str).innerHTML);