zoukankan      html  css  js  c++  java
  • 常用的一些自定义函数

     1         function $id()
     2         {
     3             var obj,name;
     4             if( arguments.length==2 )
     5             {    
     6                 obj = arguments[0];
     7                 name = arguments[1];
     8             }else if( arguments.length==1 ){
     9                 obj = document;
    10                 name = arguments[0];
    11             }else{
    12                 return alert( "$id have error!" );
    13             }
    14             return obj.getElementById(name);
    15         }
    16         
    17         function $selectedOption(obj,selectedValue)
    18         {
    19             for( var i=0;i<obj.options.length;i++ )
    20             {
    21                 if( obj.options[i].value == selectedValue )
    22                 {
    23                     obj.options[i].setAttribute("selected","true");
                           obj.selectedIndex = i; //这行代码是后来加上去的,原因在IE中找不到selectedIndex
    24                     return;
    25                 }
    26             }
    27         }
    28         
    29         function $name()
    30         {
    31             var obj,name;
    32             if( arguments.length==2 )
    33             {    
    34                 obj = arguments[0];
    35                 name = arguments[1];
                       return obj[name]!==undefined ? obj[name]:obj.getElementsByName(name);
    36             }else if( arguments.length==1 ){
    37                 obj = document;
    38                 name = arguments[0];
                       return obj.getElementsByName(name);
    39             }else{
    40                 return alert( "$name have error!" );
    41             }
    43         }
    44         
    45         function $tag()
    46         {
    47             var obj,name;
    48             if( arguments.length==2 )
    49             {    
    50                 obj = arguments[0];
    51                 name = arguments[1];
    52             }else if( arguments.length==1 ){
    53                 obj = document;
    54                 name = arguments[0];
    55             }else{
    56                 return alert( "$tag have error!" );
    57             }            
    58             return obj.getElementsByTagName(name);
    59         }
    60     
    61         String.prototype.trim = function() {
    62             var str = this,
    63             str = str.replace(/^\\s\\s*/''),
    64             ws = /\\s/,
    65             i = str.length;
    66             while (ws.test(str.charAt(--i)));
    67             return str.slice(0, i + 1);
    68         }


  • 相关阅读:
    能否获取倒数第二个指定字符的位置? 截取
    css布局之头尾固定中间高度自适应
    C# Convert.ToInt32和int.Parse转换null和空字符串时的不同表现
    当前上下文中不存在viewbag
    IIS 7.5 上传文件大小限制
    git 学习笔记
    sql like 语句
    js文件,同样的路径,拷贝过来的为什么不能访问
    软件项目开发报价(一)
    asp.net core webapi 日期返回中出现字母T
  • 原文地址:https://www.cnblogs.com/chy1000/p/1774256.html
Copyright © 2011-2022 走看看