[英]what am i doing wrong with the button?
我想在單擊按鈕時設置警報,但是當我單擊按鈕時沒有任何反應,請檢查。 即使我點擊按鈕,如果框被選中然后 foo 或者如果它沒有被選中然后 bar 但在按鈕點擊時什么也沒有發生,也應該有一個警報! - 開始片段:js hide: false console: true babel: false - ->
function myFunction(){
if (document.getElementById('foo').checked) {
alert('foo');
} else {
alert('bar');
}
}
<input type="radio" name="zing" id="foo" />
<input type="radio" name="zing" id="bar"/>
<button onclick="myFunction()">
hello
</button>
通常 onclick 是小寫的
function myFunction(){ if (document.getElementById('foo').checked) { alert('foo'); } else { alert('bar'); } }
<input type="radio" name="zing" id="foo" /> <input type="radio" name="zing" id="bar"/> <button onclick="myFunction()"> hello </button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.