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');
}

 

posted @ 2018-08-28 10:07  坚持就是胜利66  阅读(50160)  评论(1编辑  收藏  举报