简体   繁体   English

javascript复选框-仅在引导模态中取消选中

[英]javascript checkbox - uncheck only on bootstrap modal OK

I have a checkbox that I need to add some javascript to. 我有一个复选框,需要向其中添加一些JavaScript。

I am having issues getting this to work because I have a bootstrap modal that has Cancel and Confirm buttons. 我遇到了问题,因为我有一个具有“取消”和“确认”按钮的引导程序模式。

I am unsure how to pass the un-check reference to the modal code and uncheck the checkbox on on the Confirm button. 我不确定如何将取消选中的引用传递给模式代码,并取消选中“确认”按钮上的复选框。 I have made many attempts but failed on all attempts. 我做了很多尝试,但是所有尝试都失败了。

How do I do un-ceck the checkbox only when the user selects the Confirm button on the bootstrap modal. 仅当用户在引导程序模式中选择“确认”按钮时,我才能取消复选框的选择。 When the user selects the modal Cancel button, the checkbox should stay checked. 当用户选择模式取消按钮时,该复选框应保持选中状态。

Here is the checkbox code that I currently have: 这是我当前拥有的复选框代码:

<input type="checkbox" name="selected_items" value="{{ id }}" {% if selected %}checked="checked"{% endif %} data-confirm="Are you sure you want to uncheck this?" />

Here is the bootstrap modal code that I have: 这是我拥有的引导模式代码:

    $(document).ready(function() {

        $('input[data-confirm]').click(function(ev) {

            var href = $(this).attr('href');

            if (!$('#dataConfirmModal').length) {

                $('body').append('<div id="dataConfirmModal" class="modal modal-confirm-max-width" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true"><icon class="icon-remove"></icon></button><h4 class="modal-title" id="dataConfirmLabel">{% trans "Confirm" %} - {{ resume_detail_temp_value }}</h4></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "Cancel" %}</button>&nbsp;&nbsp;<a class="btn-u btn-u-blue" id="dataConfirmOK">{% trans "Confirm" %}</a></div></div>');

            }

            $('#dataConfirmModal').find('.modal-body').html($(this).attr('data-confirm'));

            $('#dataConfirmModal').modal({show:true});

            $('#dataConfirmOK').click(function() {

                // handle checkbox function here.

            });

            return false;

        });

    });

Is this what you're looking for? 这是您要找的东西吗?

$('#dataConfirmOK').click(function() {
    $('input[name=selected_items]').prop('checked', false);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM