zoukankan      html  css  js  c++  java
  • JS 构造函数中的 this

    <!doctype html >
    <html style="font-size:13.5px;">
    <head>
    <meta charset="utf-8">
    <title>JS 绑定 事件</title>
    
    </head>
    <style type="text/css">
    li{ width:500px; line-height:20px;}
    </style>
    
    
    <body>
    <ul> 
    
     <li>111111111</li>
     <li>222222222</li>
     <li>3333333333</li>
    
    </ul>
    
    
    <div id="btn"> 点击</div>
    </body>
    </html>
    
    
    <script src="jquery.1.9.0.min.js"></script>
    <script type="text/javascript">
    $(function(){
        oEditor.init();
    });
    
    var oEditor={
        //当前dom
        currentObj:{},
    };
    
    oEditor.init=function(){
        $("li").click(function(e){
                var target = $(e.target);
                oEditor.currentObj=target;  //当前DOM
                alert(oEditor.currentObj.html())
       })
        
    }
    
    
    </script>

    //上面是点击找到当前的 元素。

    //下面是   指定 当前元素  其中 主要的句

    e.target 返回触发此事件的元素(事件的目标节点)。
    var target = $(e.target);
      oEditor.currentObj=target;
    <!doctype html >
    <html style="font-size:13.5px;">
    <head>
    <meta charset="utf-8">
    <title>JS 绑定 事件</title>
    
    </head>
    <style type="text/css">
    li{ width:500px; line-height:20px;}
    .select{ background:#ccc;}
    </style>
    
    
    <body>
    <ul> 
    
     <li>111111111</li>
     <li>222222222</li>
     <li>3333333333</li>
    
    </ul>
    
    
    <div id="btn"> 点击</div>
    </body>
    </html>
    
    
    <script src="jquery.1.9.0.min.js"></script>
    <script type="text/javascript">
    $(function(){
        oEditor.init();
        
    });
    
    var oEditor={
        //当前dom
        currentObj:{},
        clear:function(){
              $("li").each(function(index, element) {
                  $(this).removeClass("select");
                
            });
        }
    };
    
    oEditor.init=function(){
        $("li").click(function(e){
                var target = $(e.target);
                oEditor.currentObj=target;
                oEditor.clear();
                oEditor.currentObj.addClass("select");
                 
       });
       
       
       $("#btn").click(function(){
            alert(oEditor.currentObj.html());
           
           })
        
    }
    
    
    </script>
  • 相关阅读:
    黑马程序员-winform视频总结的一些知识点
    如何让360兼容模式打开网页和极速模式打开一样
    [2016-10-24]jQuery学习回顾笔记1.0
    鼠标上下滑动总是放大缩小页面,按住ctrl+0
    按钮在苹果手机显示不正常
    鼠标悬停图片放大
    关于高度
    如何做出透明背景的flash动画
    复选框css
    HTML CSS 特殊字符表(转载)
  • 原文地址:https://www.cnblogs.com/yjhua/p/5069794.html
Copyright © 2011-2022 走看看