0

ラジオボックスを自動選択する jquery コードを取得できません。これが私のhtmlです:

<div class="formField rsform-block rsform-block-existingcustomer" style="margin-bottom: -22px;">

    <!--<input  name="form[existingCustomer]" type="radio" value="Yes" id="existingCustomer0"  /><label for="existingCustomer0">Yes</label><input checked="checked" name="form[existingCustomer]" type="radio" value="No" id="existingCustomer1"  /><label for="existingCustomer1">No</label><br/>
    <span id="component100" class="formNoError">Please tell us if you're an existing customer.</span>-->

    Are you an existing client?<br>
    <label for="existingCustomer0" class="radio"><span class="icon"></span><span class="icon-to-fade"></span>Yes
    <input name="form[existingCustomer]" type="radio" value="Yes" id="existingCustomer0" class="addRadio">
    </label>
    <label for="existingCustomer1" class="radio checked"><span class="icon"></span><span class="icon-to-fade"></span>No
    <input checked="checked" name="form[existingCustomer]" type="radio" value="No" id="existingCustomer1" class="addRadio" style="display:none;">
    </label>
</div>

そして、これを行うはずの jQuery コードのスニペットを次に示します。

if(aaid) {

var num_one = aaid;
jQuery('input[value="Yes"]').prop('checked', true);

誰かが問題を見ていますか?「はい」チェックボックスを自動選択して、ドロップダウンメニューを作成する次の部分をアクティブにしようとしています。

前もって感謝します!:)

4

2 に答える 2

1

これを試して:

   $(document).ready(function () {                  
     $('input:radio[name="form[existingCustomer]"][value="Yes"]').attr('checked',true);
     //OR
     $('input:radio[name="form[existingCustomer]"][value="Yes"]').prop('checked',true);
    });

于 2013-10-17T23:37:02.403 に答える
0

ここであなたのコードにいくつかの問題があります。1. 入力 hmtl に適切な終了/終了タグがありません 2. ラベルをラップする理由がわからない 3. jquery コードをドキュメントに配置して、ページが読み込まれたときにラジオボックスをチェックできるようにしてください。4. HTML コードでは、チェックするラジオを事前に設定していません。それはわざとですか?no に設定してから、jquery を使用して yes に戻したようです。

とにかく、prop の代わりに attr を試してください。このようなもの。

$('input:radio[value="Yes"]').attr('checked', true);
于 2013-10-18T00:16:33.417 に答える