下面的例子使用 INPUT type=checkbox 元素創(chuàng)建了兩個(gè)帶有解釋文本的復(fù)選框。onclick 事件將調(diào)用兩個(gè)腳本函數(shù)。第一個(gè)復(fù)選框默認(rèn)選中。
This example uses the INPUT type=checkbox element to create two check boxes with explanatory text. The onclick events call two script functions. The first check box is checked.
<INPUT TYPE=checkbox CHECKED ID=chk1 onclick="choosebox1()">Uncheck
this check box for some free advice.
<P><INPUT TYPE=checkbox ID=chk2 onclick="choosebox2()">Or check
this check box for a message from our sponsors.
<P ID=SampText>
下面的例子就是用戶單擊復(fù)選框時(shí)調(diào)用的腳本。
This example implements the script when the user clicks either check box.
<SCRIPT>
function choosebox1(){
alert("Never play leapfrog with a unicorn!")
}
function choosebox2(){
SampText.insertAdjacentHTML("AfterBegin","Buy WonderWidgets! ");當(dāng)點(diǎn)擊復(fù)先框時(shí),在復(fù)選框后自動(dòng)增加語(yǔ)句Buy WonderWidgets
}
</SCRIPT>