【问题标题】:Changing the value of a RadioButtonList using jQuery使用 jQuery 更改 RadioButtonList 的值
【发布时间】:2012-08-05 22:11:22
【问题描述】:

我已经四处搜索并找到了多个答案,但没有一个对我有用。 我在中继器控件中使用 RadioButtonList。这是我的 jQuery 函数。

$("[name$='$PlanSelectionRbtnLst']").click(function () {
    alert($(this).val());  //this works
    $("[name$='$PlanSelectionRbtnLst']").find("input[value='-1']").attr("checked", true); // this doesn't
});

当我单击任何单选按钮时,这会正确提醒我选择的值,但我无法将 RadioButtonList 的所有选定按钮更改为 -1 值。如果重要的话,我的脚本在母版页中。

编辑:根据要求,这里是渲染 html 的小 sn-p:

<table id="MainContent_BenefitsRpt_PlanSelectionRbtnLst_2>
<tbody>
    <tr>
        <td>
            <input name="ct100$MainContent$BenefitsRpt$ct103$PlanSelectionRbtnList" id="MainContent_BenefitsRpt_PlanSelectionRbtnLst_2_0_2" type="radio" value="9"/>
        </td>
    <tr>
</tbody>

【问题讨论】:

  • 发布与上述代码相关的 HTML

标签: jquery


【解决方案1】:

checked 在二进制属性中,而不是属性中。

试试:.attr("checked", "checked")

但首先,看看你的选择器是否工作:

alert($("[name$='$PlanSelectionRbtnLst']").find("input[value='-1']").length)

【讨论】:

  • 为此我得到'0'。这是否意味着它什么也没找到?应该有 3 个不同的单选按钮列表(每个都包含 -1 值),我想在点击时将其更改为 -1 值。
【解决方案2】:

试试这个:

$("[name$='$PlanSelectionRbtnLst']").click(function () {
    $("[name$='$PlanSelectionRbtnLst']")
                    .find("input[value='-1']") 
                    .prop("checked", true); 
});

【讨论】:

    猜你喜欢
    • 2013-12-26
    • 2011-12-16
    • 2015-10-22
    • 2011-08-08
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2012-06-12
    相关资源
    最近更新 更多