angular ng-click获取触发事件对象this

    xiaoxiao2021-03-25  30

    来源:http://hbiao68.iteye.com/blog/2286434

    ng-click="shareGoods({{item.goods_id}},$event)" 传递一个$event对象

    通过事件对象 $event.target  获取事件源

     

    Html代码   <div class="float_left width_50 border_b_top_eee border_b_right_eee bg_ff padding_left_15 padding_right_15 padding_top_10 line_height_15" ng-click="addPackage($event,111)">       <div class="color_e5005a font_16">洗衣机套餐1</div>       <div class="color_99">           洗衣机1台+冰箱1台       </div>       <div class="line_height_40px color_e5005a">           ¥238       </div>   </div>  

     

     

    Js代码   //动态添加数据   $scope.addPackage = function(myevent,deviceType){       //获取item对象       var htmlObj = $(myevent.target).closest(".float_left");       var deviceName = htmlObj.find("div.font_16").html();       var jsonObj = {           "deviceType":deviceType,//设备类型,唯一标识,用于判断是否已经添加           "deviceName":deviceName //设备的名称       };       //判断数据是否已经选中了       if(!this.hasDevice(deviceType)){           //给$scope.lists添加数据           this.lists.push(jsonObj);       }   };  

    转载请注明原文地址: https://ju.6miu.com/read-50185.html

    最新回复(0)