【问题标题】:How to select just a radiobutton in a repeater with postback如何在带有回发的转发器中仅选择一个单选按钮
【发布时间】:2013-12-18 18:40:58
【问题描述】:

正如我在 Internet 上发现的,当我们在中继器中添加 RadioButton 以仅选择一个时,MS 存在错误。

但我在这里找到了解决我问题的代码。 (only one radiobutton selection in repeater)

$(function () {
    $('[name$="$YourGroupName"]').attr("name", $('[name$="$YourGroupName"]').attr("name"));

    $('[name$="$YourGroupName"]').click(function () {
        //set name for all to name of clicked 
        $('[name$="$YourGroupName"]').attr("name", $(this).attr("name"));
    });
});

但它仅在单选按钮未设置为自动回发时有效。但是当我选择一个单选按钮和对数据库的响应时,我需要进行回发。但是....每当我单击带有回发的单选按钮时,总是选择列表中的第一个并且 ItemDataBound 它不起作用,因为它正在重命名具有相同名称的所有单选按钮的 jquery 函数。

建议?

【问题讨论】:

    标签: c# jquery radio-button selection repeater


    【解决方案1】:

    尝试在中继器之后添加此脚本,而不是您在页面末尾使用的脚本:

    <script> var radios = $("input:radio"); radios.click(function () { radios.removeAttr('checked'); $(this).prop("checked", true); //$(this).attr('checked', 'checked'); // jQuery < 1.6 return true; }); </script>

    这将使您的单选按钮的 AutoPostBack 再次起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-21
      • 2012-07-30
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 2013-07-30
      相关资源
      最近更新 更多