|
Larry
Moe
Curly
在該例中,如果你打算取消對一個單選框的選取,你必須點擊另一個單選框。再看下面的程序:
Light off
Light on
表單代碼如下:
<form name="form_1">
<input type="radio" name ="radio_1" onClick="offButton();">Light off
<input type="radio" name ="radio_2" onClick="onButton();" checked>Light on
</form>
當第一個單選框被選中時,函數offButton() 被調用。函數如下:
function offButton()
{
var the_box = window.document.form_1.radio_1;
if (the_box.checked == true)
{
window.document.form_1.radio_2.checked = false;
document.bgColor='black';
alert("Hey! Turn that back on!");
}
}
這個例子很象前面的復選框例子,主要的區別在于該行:
window.document.form_1.radio_2.checked = false;
該行指令指示JavaScript在該按鈕被點擊時關閉另外一個按鈕。由于另外一個按鈕的函數同這個很相似:
function onButton()
{
var the_box = window.document.form_1.radio_2;
if (the_box.checked == true)
{
window.document.form_1.radio_1.checked = false;
document.bgColor='white';
alert("Thanks!");
}
}
JavaScript技術:JavaScript初級教程(第五課續)第1/3頁,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。