jQueryを使用して<select>
に新しい「アイテム」を追加しようとしています。 両方の可能性(国)のいずれかがチェックされている場合、下の「選択ボックス」はリスト<options>
を変更する必要があります。jQueryを使用してラジオボタンが変更された場合に新しいオプションを追加する方法
$("input:radio[name=radio-1]").change(function() {
//alert ($(this).val());
if ($(this).val() == "aut") {
for (i = 18; i < 21; i++) {
$('#selectCosts').append($('<option>', {
value: i,
text: "Option " + i
}));
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="country">
<h2>Land</h2>
<form name="selectPowerCost">
<fieldset>
<div id="selectCountry" class="col col-md-12">
<!-- Österreich -->
<div class="radio pull-left" style="margin-top: -5px; min-width:150px;">
<label for="radio-1">Österreich<span class="country-aut"> </span></label>
<input class="left-20" type="radio" name="radio-1" id="radio-1" value="aut">
</div>
<!-- Deutschland -->
<div class="radio pull-left left-10" style="min-width:150px;">
<label for="radio-2">Deutschland<span class="country-ger"> </span></label>
<input class="left-20" type="radio" name="radio-1" id="radio-2" value="ger">
</div>
</div>
</fieldset>
</form>
</div>
<div id="stromkostenProKW">
<h2>Stromkosten pro KWh</h2>
<div class="pull-left" style="margin-top: -5px">
<form>
<select id="selectCosts" name="selectCosts" class="selectpicker" title="Wählen Sie Ihre Stromkosten pro KWh">
\t \t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t \t </select>
</form>
</div>
</div>
このコードwon`tラン:
は、これは私のコードです。どうして?
通常のhtmlをこのように追加してみましたか? Option '+ i +' ');' –
このように通常のHTMLを追加してみましたか? Option '+ i +' ');' –
@ThomasWeber私はあなたを助けましたか? – Miles07