1 回答

TA貢獻2065條經驗 獲得超14個贊
innerHTML使用 vanilla JS 時使用。您應該在 jQuery 引用的對象上使用text()。您也不需要在此處附加。
我也相信你用錯了.one(),應該是的.on()。
$('input[type="radio"]').on('click', function () {
var getVal = $(this).val();
if ($('.selections').text().length < 0) {
//console.log('less than');
} else if ($('.selections').text().length > 0){
//console.log('more than');
$('.selections').text(getVal);
}
//console.log(getVal);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
<label>
<span class="radio-c">
<input type="radio" name="q1" value="Between £381K and £450K" id="between381">
Between £381K and £450K
</span>
</label>
<label>
<span class="radio-c">
<input type="radio" name="q1" value="Over £450K" id="over450">
Over £450K
</span>
</label>
</form>
<div class="selections">
</div>
添加回答
舉報