在复选框选中更改时显示引导对话框

Show bootstrap Dialog on Checkbox Check Change

本文关键字:显示 对话框 复选框      更新时间:2023-09-26

这是我的Jquery代码。我想在用户选中或取消选中复选框时显示引导程序确认对话框。我该怎么做?

  $("#chkAdmin").change(function () {     
        if (this.checked) {               
            $("#divAdmin").find("*").prop("disabled", true);
        } else {
            $("#divAdmin").find("*").prop("disabled", false);
        }
    });

我想先显示bootrap Yes No模态,基于Yes或No,我想执行上面的代码。

试试这个

  $("#chkAdmin").change(function () {     
    if ($(this).prop('checked')) {  
        var answer = confirm("Are you sure?")
        if (answer){
            alert("Yes")
             $("#divAdmin").show();
        }
        else{
            alert("No");
             $("#divAdmin").hide();
        }
    } 
});

试试这个:

$("#chkAdmin").change(function () {     
        if ($(this).prop('checked')) {  
            $("#divAdmin").show();
        } else {
            $("#divAdmin").hide();
        }
    });

试试这个:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- stylesheets -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- javascript/jQuery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.3.0/respond.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
    <form action="http://localhost.testing/modal-processing.php" class="col-sm-6 form-horizontal" role="form" method="GET">
        <label>Landlord<span class="mandatory">*</span></label>
        <!-- modal caller -->
        <input type="checkbox" href="#modal-dialog" class="modal-toggle" data-toggle="modal" data-href="http://localhost.testing/modal-processing.php" data-modal-type="confirm" data-modal-title="Delete Property" data-modal-text="Are you sure you want to delete {$property.address_string}?" data-modal-confirm-url="{$base_url}/id/{$property.id}"><i class="icon-trash"></i> Modal Submit</a>
    </form>
</div>
<div id="modal-dialog" class="modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <a href="#" data-dismiss="modal" aria-hidden="true" class="close">×</a>
                <h3>Are you sure</h3>
            </div>
            <div class="modal-body">
                <p>Do you want to submit the form?</p>
            </div>
            <div class="modal-footer">
                <a href="#" id="btnYes" class="btn confirm">Yes</a>
                <a href="#" data-dismiss="modal" aria-hidden="true" class="btn secondary">No</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>