javascript - How to handle repeated binding events?

WBOY
Release: 2023-03-01 18:16:01
Original
1227 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

<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>
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

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

<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>
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

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">&lt;code class=&quot;javascript&quot;&gt;var currentCart = -1;//默认-1 $('#cards').on('click','.btnJieBang',function(){ currentCart=this.dataset.cartid; }); //弹窗确定的事件里,去读取currentCart变量即可&lt;/code&gt;</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

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
Popular Tutorials
More>
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!