28个常用JavaScript方法集锦(8)


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, "");}

/* js 动态移除 head 里的 js 引用  */

复制代码 代码如下:


this.ClearHeadJs = function (src) {
    var js = document.getElementsByTagName('head')[0].children;
    var obj = null;
    for (var i = 0; i < js.length; i++) {
        if (js[i].tagName.toLowerCase() == "script" && js[i].attributes['src'].value.indexOf(src) > 0) {
            obj = js[i];
        }
    }
    document.getElementsByTagName('head')[0].removeChild(obj);
};

  

/*  整个UL 点击事件  加在UL里的onclick里 */

复制代码 代码如下:


function CreateFrom(url, params) {
     var f = document.createElement("form");
     f.setAttribute("action", url);
     for (var i = 0; i < params.length; i++) {
         var input = document.createElement("input");
         input.setAttribute("type", "hidden");
         input.setAttribute("name", params[i].paramName);
         input.setAttribute("value", params[i].paramValue);
         f.appendChild(input);
     }
     f.target = "_blank";
     document.body.appendChild(f);
     f.submit();
 };

/* 判断浏览器使用的是哪个 JS 版本 */

复制代码 代码如下:


<script language="javascript">
      var jsversion = 1.0;
    </script>
    <script language="javascript1.1">
      jsversion = 1.1;
    </script>
    <script language="javascript1.2">
      jsversion = 1.2;
    </script>
    <script language="javascript1.3">
      jsversion = 1.3;
    </script>
    <script language="javascript1.4">
      jsversion = 1.4;
    </script>
    <script language="javascript1.5">
      jsversion = 1.5;
    </script>
    <script language="javascript1.6">
      jsversion = 1.6;
    </script>
    <script language="javascript1.7">
      jsversion = 1.7;
    </script>
    <script language="javascript1.8">
      jsversion = 1.8;
    </script>
    <script language="javascript1.9">
      jsversion = 1.9;
    </script>
    <script language="javascript2.0">
      jsversion = 2.0;
    </script>
alert(jsversion);

以上就是本文的全部内容了,希望能对大家有所帮助,也不枉整理这么久了,呵呵。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxwsf.html