如何使用 jQuery 在复选框列表中仅选择 MCV 3 中选定的一项

发布于 2024-12-20 22:12:54 字数 1205 浏览 5 评论 0原文

我开发了一个 MVC3 应用程序,我想在其中使用复选框列表,我有三个复选框。我的要求是,当我选中复选框时,它仅接受复选框,而不应像 RadioButton 列表类型那样取消选中多个剩余复选框。

请帮助我...我该如何解决这个问题?

这是我的查看代码

           @{
ViewBag.Title = "MenuCategories";
Layout = "~/Views/Shared/_Layout.cshtml";
 }

  <script type="text/javascript">
$(function () {
    enable_cb();
    $("#ChbkPickup").click(enable_cb);
});

function enable_cb() {
    if (this.checked) {
        $("input.ccc").removeAttr("disabled");
    } else {
        $("input.group1").attr("disabled", true);
    }
}
$(function () {


    $('.example-container > pre').each(function (i) {
        eval($(this).text());
    });
});

 </script>



         @using (Html.BeginForm("OrderCompleted", "Home", FormMethod.Post, new { id = "myForm" }))
             {
                  @Html.ValidationSummary(true)



              Delivery:<input type="checkbox" name="Deliver" value="Deliver" id="Chbkdeliver" />
             Pickup: <input type="checkbox" name="Deliver" value="Pickup" id="ChbkPickup" class="group1"  checked="checked" />
             Dine In:<input type="checkbox" name="Deliver" value="Dinein" class="group1" id="ChbkDinein" />
 }

I have developed a MVC3 application in that I want use the Check boxlist in this I have three check boxes. My requirement is when I check the check box it accept only on check box not multiple remaining check box should be unchecked like RadioButton list type.

Please help me... How can I resolve this problem?

Here is my view code

           @{
ViewBag.Title = "MenuCategories";
Layout = "~/Views/Shared/_Layout.cshtml";
 }

  <script type="text/javascript">
$(function () {
    enable_cb();
    $("#ChbkPickup").click(enable_cb);
});

function enable_cb() {
    if (this.checked) {
        $("input.ccc").removeAttr("disabled");
    } else {
        $("input.group1").attr("disabled", true);
    }
}
$(function () {


    $('.example-container > pre').each(function (i) {
        eval($(this).text());
    });
});

 </script>



         @using (Html.BeginForm("OrderCompleted", "Home", FormMethod.Post, new { id = "myForm" }))
             {
                  @Html.ValidationSummary(true)



              Delivery:<input type="checkbox" name="Deliver" value="Deliver" id="Chbkdeliver" />
             Pickup: <input type="checkbox" name="Deliver" value="Pickup" id="ChbkPickup" class="group1"  checked="checked" />
             Dine In:<input type="checkbox" name="Deliver" value="Dinein" class="group1" id="ChbkDinein" />
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2024-12-27 22:12:54

用这个替换你所有的 javascript 标签

<script type="text/javascript">
   $(function () {
      $("#myform :checkbox").click(function(){
        $("#myform input:checked").attr("checked","");
        $(this).attr("checked","checked");
      });
   });

 </script>

replace all your javascript tag with this

<script type="text/javascript">
   $(function () {
      $("#myform :checkbox").click(function(){
        $("#myform input:checked").attr("checked","");
        $(this).attr("checked","checked");
      });
   });

 </script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文