zoukankan      html  css  js  c++  java
  • js点击事件获取当前元素或父级元素

    1.通过设定标签,在js里写click事件

    html:

    <div style="margin-left: 77px; background-color: white; line-height: 30px; padding-left: 5px;">
         <a class="pro deleteBrand" title="适用季节" href="javascript:void(0);">适用季节
            <span class="icon-btn-x">x</span>
         </a>
         <a class="pro deleteBrand" title="适用季节" href="javascript:void(0);">适用季节
             <span class="icon-btn-x">x</span>
         </a>
         <a class="pro deleteBrand" title="适用季节" href="javascript:void(0);">适用季节
             <span class="icon-btn-x">x</span>
         </a>
         <a class="pro" id="btn-brand-search" title="适用季节" href="javascript:void(0);">更多∨</a>
      </div>

    js:

    deleteBrand : function () {
      $(".deleteBrand").click(function (aa) {
         $(this).css('display', 'none');
       //$(this).parent().css('display', 'none');
      });
    }

    2.在html页面写click事件

    html:

    <div style="margin-left: 77px; background-color: white; line-height: 30px; padding-left: 5px;">
       <a class="pro" data-url="nav"  title="适用季节" href="javascript:void(0);" onclick="new goodsUpperAndLower.init().deleteBrand(this);">适用季节
           <span class="icon-btn-x">x</span>
       </a>
       <a class="pro" data-url="nav"  title="适用季节" href="javascript:void(0);" onclick="new goodsUpperAndLower.init().deleteBrand(this);">适用季节
           <span class="icon-btn-x">x</span>
       </a>
       <a class="pro" data-url="nav"  title="适用季节" href="javascript:void(0);" onclick="new goodsUpperAndLower.init().deleteBrand(this);">适用季节
           <span class="icon-btn-x">x</span>
       </a>
       <a class="pro" id="btn-brand-search" title="适用季节" href="javascript:void(0);">更多∨</a>
     </div>

    js:

    deleteBrand : function (obj) {
       //$(obj).parent().css('display', 'none');
       $(obj).css('display', 'none');
    }
  • 相关阅读:
    实战-百度云[大文件/文件夹]下载限制破解
    IOCP之客户端及消息传递
    IOCP简单实现
    Charles V4系列更新 | 绿色特别版 | 视频教程
    Charles 3.11.5 绿色特别版
    VC运行库合集2005/2008/2010/2012/2013/2015
    手游测试之《弱网测试》
    后端性能测试不可不知的二三事
    linux性能指标及分析工具
    Shell笔记-04
  • 原文地址:https://www.cnblogs.com/jcjssl/p/9546370.html
Copyright © 2011-2022 走看看