0

所以我有一个带有表单的模态。该表单有两个单选按钮:

在此处输入图像描述

我有这个,如果用户在其中单击,它会阻止模式关闭:

$(".modal-content").click(function(e){
    return false;
});

但是,这会阻止选择单选按钮(在 FF 中),并且在 Google/ Fiddle中您可以选择一次,但不能再次选择。

有谁知道解决这个问题的方法?

我试过这个:

$("input:radio").click(function(e){
    return true;
});

但它没有用。

这是一些代码和小提琴

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        // Prevents the modal from closing if the user clicks inside the white box
        $(".modal-content").click(function(e){
            return false;
        });
        $("input:radio").click(function(e){
            console.log("working");
            return true;
        });
    });
</script>

Normal Buttons <br/>
<input type="radio" name="test"><span>Yes</span>
<input type="radio" name="test"><span>No</span><br/><br/>

Return false buttons:<br/>
<div style="border: 1px black solid;" class="modal-content">
    <input type="radio" name="loan"><span>Yes</span>
    <input type="radio" name="loan"><span>No</span>
    <br/><br/>
</div>
4

2 回答 2

2

您必须停止传播,否则它将永远无法工作。

$("input:radio").click(function(e){
    e.stopPropagation();
});
于 2013-05-23T16:33:35.903 回答
0

抱歉,刚刚找到答案。你必须使用 stopPropagation(); 而不是返回false,所以:

$(".modal-content").click(function(e){
    e.stopPropagation();
    //return false;
});
于 2013-05-23T16:29:35.413 回答