按复选框打开 bootstrap 模式?

Open a bootstrap modal by pressing a checkbox?

我搜索打开带有复选框的模式 #LoginModalStart,但页面打开此模式时带有每个复选框。

你能帮帮我吗?

$('input[type="checkbox"]').on('change', function(e) {
            if (e.target.checked) {
                $("#LoginModalScreenplay").modal();
            }
        });

您必须将 show 传递给 modal 方法:

$('#LoginModalScreenplay').modal('show')

$('input[type="checkbox"]') 以您页面上的 每个 复选框为目标。您可能想要定位特定的复选框。像这样

<input type="checkbox" id="my-special-checkbox">
$('#my-special-checkbox').on('change', function(e) {
            if (e.target.checked) {
                $("#LoginModalScreenplay").modal();
            }
        });

你用这个,

<input name="checkbox" type="checkbox" id="my-special-checkbox" value=1>
<input name="checkbox" type="checkbox" id="my-special-checkbox" value=2>
<input  name="checkbox" type="checkbox" id="my-special-checkbox" value=3>

<script>
$(document).ready(function(){
    $('input[name="checkbox"]').on('change', function(e) {
        var x = $(this).val();
        $("input:checkbox").prop('checked', false);

        if(x==1){
            $("input[value="+x+"]").prop('checked', true);
            $("#LoginModalScreenplay").modal(); //or $("#LoginModalScreenplay").show();
        }
    });
});
</script>