2016-07-28 13 views
-1

私のダッシュボードには4つのラジオボタンがあります。 1つの条件で1つだけを表示する必要があります。各ボタンの値は異なります値を使用してラジオボタンを削除します

<input type="radio" name="payment_method" id="payment_method" value="Online-Others"> 
<input type="radio" name="payment_method" id="payment_method" value="Cash"> 
<input type="radio" name="payment_method" id="payment_method" value="wallet"> 
<input type="radio" name="payment_method" id="payment_method" value="online"> 

ここでは現金ボタンのみを表示する必要があります。各ボタンに異なるIDを付ける必要がありますか?それとも、これを使って私はそれを示すことができますか?

+0

何を試しましたか? – nicael

+4

IDは一意である必要があります。 –

+1

'ids'はユニークです! – eisbehr

答えて

0

あなたは属性セレクタと値によって要素を削除することができます

// removes all 'payment_method' radios where 'value' is not 'Cash' 
$(".payment_method[value!=Cash]").remove(); 

をしかしidsはHTMLで一意であるとして、あなたは(必須)よりよいそれらを変更することができます:

<input type="radio" name="payment_method" id="payment_method_others" value="Online-Others"> 
<input type="radio" name="payment_method" id="payment_method_cash" value="Cash"> 
<input type="radio" name="payment_method" id="payment_method_wallet" value="wallet"> 
<input type="radio" name="payment_method" id="payment_method_online" value="online"> 

JSを:

// removes all 'payment_method' radios where 'id' is not 'payment_method_cash' 
$(".payment_method:not(#payment_method_cash)").remove(); 
0

IDまたはClaを追加する必要はありませんss

 
    $('input[name=payment_method][value=wallet]').prop('checked',true); //if you need to highlight "wallet" 
    $('input[name=payment_method][value=Cash]').prop('checked',true); //if you need to highlight "Cash" 

0

あなたの質問はあまり明確ではありませんが、このようなことは期待していますか?

$('#payment_method_cash').on('change', function() { 
 

 
    // Show cash payment button and options. 
 
    console.log('Cash option checked : ' + $(this).prop('checked')); 
 
}); 
 

 
$('#payment_method_wallet').on('change', function() { 
 

 
    // Show wallet payment button and options. 
 
    console.log('wallet option checked : ' + $(this).prop('checked')); 
 
}); 
 

 
$('#payment_method_online').on('change', function() { 
 

 
    // Show online payment button and options. 
 
    console.log('online option checked : ' + $(this).prop('checked')); 
 
}); 
 

 

 
$('#payment_method_other').on('change', function() { 
 

 
    // Show other payment button and options. 
 
    console.log('Other option checked : ' + $(this).prop('checked')); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="radio" name="payment_method" id="payment_method_other" value="Online-Others"> 
 
<input type="radio" name="payment_method" id="payment_method_cash" value="Cash"> 
 
<input type="radio" name="payment_method" id="payment_method_wallet" value="wallet"> 
 
<input type="radio" name="payment_method" id="payment_method_online" value="online">

0

あなたはid属性を削除することができますし、value属性を使用することができます。あなたはjqueryの下の4回の使用のうちの1つのラジオボタンをチェックしたい場合は

HTML

<input type="radio" name="payment_method" value="Online-Others"> 
<input type="radio" name="payment_method" value="Cash"> 
<input type="radio" name="payment_method" value="wallet"> 
<input type="radio" name="payment_method" value="online"> 

jqueryのコードを交互に

//if you want to show only Cash radio button 

$(document).ready(function() { 
    $("input[value!='Cash']").css('display','none'); 
}); 

のようになります。

//if you want to checked Cash radio button out of four use below 

$(document).ready(function() { 
    $("input[value='Cash']").attr('checked','true'); 
    }); 

希望します。

関連する問題