zoukankan      html  css  js  c++  java
  • javaScript学习笔记之 javaScript 常见方法 记录

    1: 20110602

       ps:阻止事件冒泡

       

    function stopBuble(e){
       
    if(e && e.stopPropagation){
            e.stopPropagation();   
       }
       
    else 
         window.event.cancelBubble 
    = true;
    }

    2: 20110602

       ps:删除指定元素的所有的节点

    function removeElement (id){
       
    var elem = document.getElementById(id);
       
    if(elem){
            
    while (elem.hasChildModes()){
                elem.removeChild(elem.lastChild);    
            }
            elem.parentNode.removeChild(elem);
       }
    }

    感觉 这个还是有问题 因为没有办法删除第二层子节点  如果该节点绑定了事件还是会导致内存泄露 (大家有啥好的办法。欢迎共享)

     3:20110602

        PS:阻止事件冒泡方法

    function stopDeafult(e){
       
    if(e && e.preventDefault){
           e.preventDefault();
       }
       
    else 
           window.event.returnValue 
    = false;
       
    return false;
    }

      

     4:20110705

        PS:关闭浏览器

     function closeWindow() {  
         window.opener 
    = null;  
         window.open(
    '''_self''');  
         window.close();  
     }

     注意:这个在关闭火狐浏览器的时候会出现问题。需要手动设置下火狐配置

    5:20120203

         ps:获取浏览器窗口大小

    function getBrowserWindowSize(){
        var de = document.documnetElement;
        return {
            'width':(
                window.innerWidth || (de && de.clientWidth) || document.body.clientWidth
            ),

            'height':( 

                window.innerHeight || (de && de.clientHeight) || document.body.clientHeight
            )
        }

    6:20130314

         ps:删除数组中的指定元素

      

    fnRemoveByKey:function(array,key){
        var iIndex = array.indexOf(key); 
        if (iIndex >= 0) { 
            array.splice(iIndex, 1); 
        } 
        return array;
    }

    PS:以上纯属个人观点。如果有啥问题。欢迎博友拍砖。大家共同进步! 谢谢 

  • 相关阅读:
    Visual Studio 2013 的 Xamarin 安装教程
    BeesCMS后台登录SQL报错注入
    Linux系统更改IP地址
    SSRF漏洞
    代码执行漏洞
    Python零碎的知识(持续更新)
    iptables
    WAF学习_(2)安装
    WAF学习_(1)Lua基础
    SSL协议
  • 原文地址:https://www.cnblogs.com/blueSkys/p/2068799.html
Copyright © 2011-2022 走看看