0

私は周りを検索して、これに対する複数の答えを見つけましたが、それらのどれも私のために働いていません。リピーターコントロール内で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の小さなスニペット:

<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>
4

2 に答える 2

1

checked属性ではなく、バイナリ プロパティで。

試す: 。attr("checked", "checked")

ただし、最初に、セレクターが機能しているかどうかを確認してください。

alert($("[name$='$PlanSelectionRbtnLst']").find("input[value='-1']").length)
于 2012-08-08T18:27:40.457 に答える
0

これを試して:

$("[name$='$PlanSelectionRbtnLst']").click(function () {
    $("[name$='$PlanSelectionRbtnLst']")
                    .find("input[value='-1']") 
                    .prop("checked", true); 
});
于 2012-08-08T18:33:08.443 に答える