私は3つのラジオボタンを持っています。 1つ目のラジオボタン(つまりsel_address)をクリックするたびにページを更新したい。ユーザーが選択したアドレスをクリックするとページが更新されるはずです。他の2つのラジオボタンをクリックしてページをリフレッシュする必要はありません。これを達成するには?最初のラジオボタンで、更新ページをクリック
$("input[name='delivery_option']").eq(0).click(function() {
console.log('First was clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class="option sel_address">
<input type="radio" value="sel_address" name="delivery_option" id="sel_address">
</label>
<strong>selected address</strong>
<label class="option your_school">
<input type="radio" value="your_school" name="delivery_option" id="your_school">
</label>
<strong>school</strong>
<label class="option rhs_showroom">
<input type="radio" value="showroom" name="delivery_option" id="showroom">
</label>
<strong>Showroom</strong>
または:first
pseudo class selector:
<label class="option sel_address">
<input type="radio" value="sel_address" name="delivery_option" checked="checked" id="sel_address">
</label>
<strong>selected address</strong>
<label class="option your_school">
<input type="radio" value="your_school" name="delivery_option" id="your_school">
</label>
<strong>school</strong>
<label class="option rhs_showroom">
<input type="radio" value="showroom" name="delivery_option" id="showroom">
</label>
<strong>Showroom</strong>
<script type="text/javascript">
$("input[name='delivery_option']").click(function() {
.
.
var delivery_value = $(this).val();
if(delivery_value == "your_school" || delivery_value == "showroom"){
//some code
}else{
..
}
}
'に見て:first'セレクター:https://api.jquery.com/first-selector/ – BeNdErR