我有下面的代碼,顯示警告「未定義」,直到在下拉列表中選擇了一個選項。有沒有辦法阻止此消息出現?如何禁止jQuery「undefined」消息
<select id="currency" required>
<option value="" selected disabled>Select Currency</option>
<option value="1,$">USD</option>
<option value="1,£">GBP</option>
</select>
<p><span id='symbol1'></span>0.00</p>
<script>
$(document).ready(currencyFunction);
document.getElementById("currency").addEventListener("change", currencyFunction);
function currencyFunction() {
select=document.getElementById('currency').value.split(',');
display = select[1];
document.getElementById("symbol1").innerHTML = display;
}
</script>
什麼是不確定的錯誤?第二,也許你需要添加'var'來選擇和顯示 –
爲什麼你需要在文檔準備好時運行'currencyFunction'?它試圖解析你的默認值,它是'''',並且當你嘗試從它獲得第二個值時失敗。 –
@EvanKnowles這超級簡單 - 謝謝! –