String.prototype.stripslashes = function(){ return this.replace(/<.*?>/g, ''); }; String.prototype.htmlspecialchars = function(){ var str = this.replace(/&/g, '&'); str = str.replace(//g, '>'); str = str.replace(/"/g, '"'); return str; }; //使用范例: var str = 'my personal website: '; str += 'jonasjohn.de'; document.write("Original string (html): '" + str + "'

"); var str_no_html = str.stripslashes(); document.write("- String without HTML tags: '" + str_no_html + "'
"); var str_hsc = str.htmlspecialchars(); document.write("- String with converted HTML tags: '" + str_hsc + "'"); //javascript/2098