- String.prototype.lTrim = function() {
- return this.replace(/^\\s*/, "");
- }
-
- String.prototype.rTrim = function() {
- return this.replace(/\\s*$/, "");
- }
-
- String.prototype.trim = function() {
- return this.lTrim().rTrim();
- }
-
- //或者
-
- String.prototype.trim= function() {
- return this.replace(/(^\\s*)|(\\s*$)/g, "");
- }
-
- /*** 返回字节数 ***/
- String.prototype.lenB = function() {
- return this.replace(/[^\\x00-\\xff|·]/g, "**").length;
- }
- //alert("中国".lenB()); //out 4
-
- String.prototype.stripTags = function() {
- return this.replace(/<\\/?[^>]+>/gi, "");
- }
-
- String.prototype.escapeXML = function() {
- return this.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """).replace(/'/g, "'");
- }
- function XMLEscape(s) {
- s = s.replace(/&/g, "&");
- s = s.replace(/>/g, ">");
- s = s.replace(/</g, "<");
- s = s.replace(/"/g, """);
- s = s.replace(/'/g, "'");
- return s;
- }
-
- function URLEncode(plaintext) {
- var SAFECHARS = "0123456789" + // Numeric
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
- "abcdefghijklmnopqrstuvwxyz" +
- "-_.!~*'()"; // RFC2396 Mark characters
- var HEX = "0123456789ABCDEF";
- var encoded = "";
- for (var i = 0; i < plaintext.length; i++ ) {
- var ch = plaintext.charAt(i);
- if (ch == " ") {
- encoded += "+"; // x-www-urlencoded, rather than %20
- } else if (SAFECHARS.indexOf(ch) != -1) {
- encoded += ch;
- } else {
- var charCode = ch.charCodeAt(0);
- if (charCode > 255) {
- encoded += "+";
- } else {
- encoded += "%";
- encoded += HEX.charAt((charCode >> 4) & 0xF);
- encoded += HEX.charAt(charCode & 0xF);
- }
- }
- } // for
- return encoded;
- }
(iwgh) |