下面的例子使用 INPUT type=checkbox 元素创建了两个带有解释文本的复选框。onclick 事件将调用两个脚本函数。第一个复选框默认选中。
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>
下面的例子就是用户单击复选框时调用的脚本。
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! ");当点击复先框时,在复选框后自动增加语句Buy WonderWidgets
}
</SCRIPT>