<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>

            Javascript拓展String方法代碼

            時間:2024-06-08 16:52:17 JavaScript 我要投稿
            • 相關推薦

            Javascript拓展String方法代碼

              復制代碼 代碼如下:

              String.prototype.EndWith = function (str) {

              if (str == null || str == "" || this.length == 0 || str.length > this.length)

              return false;

              if (this.substring(this.length - str.length) == str)

              return true;

              else

              return false;

              return true;

              }

              String.prototype.StartWith = function (str) {

              if (str == null || str == "" || this.length == 0 || str.length > this.length)

              return false;

              if (this.substr(0, str.length) == str)

              return true;

              else

              return false;

              return true;

              }

              String.prototype.Trim = function () {

              return this.replace(/(^s*)|(s*$)/g, "");

              }

              String.prototype.ltrim = function () {

              return this.replace(/(^s*)/g, "");

              }

              String.prototype.rtrim = function () {

              return this.replace(/(s*$)/g, "");

              }

              String.format = function (str) {

              var i = 1, args = arguments;

              var str = args[0];

              var re = /{(d+)}/g;

              return str.replace(re, function () { return args[i++] });

              };

              var Json2string = function (obj) {

              var t = typeof (obj);

              if (t != "object" || obj === null) {

              // simple data type

              if (t == "string") obj = " + obj + ";

              return String(obj);

              }

              else {

              // recurse array or object

              var n, v, json = [], arr = (obj && obj.constructor == Array);

              for (n in obj) {

              v = obj[n]; t = typeof (v);

              if (t == "string") v = " + v + ";

              else if (t == "object" && v !== null)

              v = Json2string(v);

              json.push((arr ? "" : " + n + :") + String(v));

              }

              return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");

              }

              };

            【Javascript拓展String方法代碼】相關文章:

            高效編寫JavaScript代碼的技巧08-25

            在Java中執行JavaScript代碼07-14

            JavaScript實現網頁刷新代碼段08-07

            int和String互相轉換的方法08-05

            JavaScript常用方法匯總10-25

            常用排序算法之JavaScript實現代碼段06-04

            網頁程序設計之實用JavaScript代碼段09-23

            JavaScript數組常用方法介紹09-04

            javascript跨域訪問的方法07-09

            javascript編程異常處理的方法08-04

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院