javascript - How to handle repeated binding events?

WBOY
Release: 2023-03-01 18:16:01
Original
1171 people have browsed it

javascript - How to handle repeated binding events?
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

 

建设银行

储蓄卡

**** **** ****

解绑

建设银行

储蓄卡

**** **** ****

解绑

建设银行

储蓄卡

**** **** ****

解绑

确定解绑该银行卡吗?


取消
确认
Copy after login
Copy after login
javascript - How to handle repeated binding events?
Reply content:

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

 

建设银行

储蓄卡

**** **** ****

解绑

建设银行

储蓄卡

**** **** ****

解绑

建设银行

储蓄卡

**** **** ****

解绑

确定解绑该银行卡吗?


取消
确认
Copy after login
Copy after login
javascript - How to handle repeated binding events?

用 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(); }); 
Copy after login
javascript - How to handle repeated binding events?If possible, I hope you will adopt it
It’s very simple. When the user clicks to unbind, you can bind the information of which bank card the user clicked to the properties of the pop-up box label. For example, you can bind the bank card serial number to it, like this

. When the user clicks to confirm, you can just go to the top to get it.

Get the

DOMJavaScript event object

through

event.target

orevent.currentTargetUse a variable to save the currently operated card.

<code class="javascript">var currentCart = -1;//默认-1 $('#cards').on('click','.btnJieBang',function(){ currentCart=this.dataset.cartid; }); //弹窗确定的事件里,去读取currentCart变量即可</code>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!