JavaScript初級教程(第五課續(xù))第1/3頁
在該例中,如果你打算取消對一個單選框的選取,你必須點(diǎn)擊另一個單選框。再看下面的程序:
<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>
當(dāng)?shù)谝粋€單選框被選中時,函數(shù)offButton() 被調(diào)用。函數(shù)如下:
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!");
}
}
這個例子很象前面的復(fù)選框例子,主要的區(qū)別在于該行:
window.document.form_1.radio_2.checked = false;
該行指令指示JavaScript在該按鈕被點(diǎn)擊時關(guān)閉另外一個按鈕。由于另外一個按鈕的函數(shù)同這個很相似:
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!");
}
}
相關(guān)文章
document 和 document.all 分別什么時候用
document 和 document.all 分別什么時候用...2006-09-09JavaScript腳本語言在網(wǎng)頁中的簡單應(yīng)用
JavaScript腳本語言在網(wǎng)頁中的簡單應(yīng)用...2007-05-05一個簡單的網(wǎng)站訪問JS計數(shù)器 刷新1次加1次訪問
一個簡單的網(wǎng)站訪問JS計數(shù)器,一般就是學(xué)習(xí)下原來,不建議使用,現(xiàn)在cnzz或百度統(tǒng)計多試不錯的2012-09-09深入理解JavaScript系列(30):設(shè)計模式之外觀模式詳解
這篇文章主要介紹了深入理解JavaScript系列(30):設(shè)計模式之外觀模式詳解,外觀模式(Facade)為子系統(tǒng)中的一組接口提供了一個一致的界面,此模塊定義了一個高層接口,這個接口值得這一子系統(tǒng)更加容易使用,需要的朋友可以參考下2015-03-03