The unbinding pop-up window is public. When I click confirm and cancel, how do I know that the corresponding bank card click is the unbinding (corresponding bank card dom removal) operation
<code><!-- 银行卡列表 --> <div class="bankcard-block"> <div class="bankcard-item"> <img class="card-img" src="<{$style}>statics/images/yinlianzhifuicon.png"> <div class="card-info"> <p class="card-name">建设银行</p> <p class="card-type">储蓄卡</p> <p class="card-number">**** **** **** <label>6535</label></p> </div> <div class="ubind-card">解绑</div> </div> </div> <div class="bankcard-block"> <div class="bankcard-item"> <img class="card-img" src="<{$style}>statics/images/yinlianzhifuicon.png"> <div class="card-info"> <p class="card-name">建设银行</p> <p class="card-type">储蓄卡</p> <p class="card-number">**** **** **** <label>6535</label></p> </div> <div class="ubind-card">解绑</div> </div> </div> <div class="bankcard-block"> <div class="bankcard-item"> <img class="card-img" src="<{$style}>statics/images/yinlianzhifuicon.png"> <div class="card-info"> <p class="card-name">建设银行</p> <p class="card-type">储蓄卡</p> <p class="card-number">**** **** **** <label>6535</label></p> </div> <div class="ubind-card">解绑</div> </div> </div> <!-- 解绑成功 --> <div class="unbind-confirm"> <p>确定解绑该银行卡吗?</p> <hr> <div class="unbind-option clearfix"> <div class="unbind-cancel">取消</div> <div class="unbind-sure">确认</div> </div> </div></code>
<code><!-- 银行卡列表 --> <div class="bankcard-block"> <div class="bankcard-item"> <img class="card-img" src="<{$style}>statics/images/yinlianzhifuicon.png"> <div class="card-info"> <p class="card-name">建设银行</p> <p class="card-type">储蓄卡</p> <p class="card-number">**** **** **** <label>6535</label></p> </div> <div class="ubind-card">解绑</div> </div> </div> <div class="bankcard-block"> <div class="bankcard-item"> <img class="card-img" src="<{$style}>statics/images/yinlianzhifuicon.png"> <div class="card-info"> <p class="card-name">建设银行</p> <p class="card-type">储蓄卡</p> <p class="card-number">**** **** **** <label>6535</label></p> </div> <div class="ubind-card">解绑</div> </div> </div> <div class="bankcard-block"> <div class="bankcard-item"> <img class="card-img" src="<{$style}>statics/images/yinlianzhifuicon.png"> <div class="card-info"> <p class="card-name">建设银行</p> <p class="card-type">储蓄卡</p> <p class="card-number">**** **** **** <label>6535</label></p> </div> <div class="ubind-card">解绑</div> </div> </div> <!-- 解绑成功 --> <div class="unbind-confirm"> <p>确定解绑该银行卡吗?</p> <hr> <div class="unbind-option clearfix"> <div class="unbind-cancel">取消</div> <div class="unbind-sure">确认</div> </div> </div></code>
<code>用 jquery 的 方式 $('.ubind-card').click(function(){ //的到当前银行卡列表的下标 var ubindIndex = $(this).parents('.bankcard-block').index(); //给确定按钮赋一个标识 $('.unbind-sure').attr('val',ubindIndex ).show(); }); $('.unbind-sure').click(function(){ var index = $(this).attr('val'); $('.bankcard-block:eq('+index+')').remove(); }); </code>
. When the user clicks to confirm, you can just go to the top to get it.
Get the
DOMJavaScript event object
event.target
or event.currentTarget
Use a variable to save the currently operated card.
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code class="javascript">var currentCart = -1;//默认-1
$('#cards').on('click','.btnJieBang',function(){
currentCart=this.dataset.cartid;
});
//弹窗确定的事件里,去读取currentCart变量即可</code></pre><div class="contentsignin">Copy after login</div></div>
When you click Unbind, you can get its parent element, and then delete the parent element through related operations to achieve the goal.
Add a distinguishable data-id after unbinding
Bind a unique identifier