JavaScript初级教程(第五课续)第1/3页
在该例中,如果你打算取消对一个单选框的选取,你必须点击另一个单选框。再看下面的程序:
<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!");
}
}
相关文章
document 和 document.all 分别什么时候用
document 和 document.all 分别什么时候用...2006-09-09深入理解JavaScript系列(30):设计模式之外观模式详解
这篇文章主要介绍了深入理解JavaScript系列(30):设计模式之外观模式详解,外观模式(Facade)为子系统中的一组接口提供了一个一致的界面,此模块定义了一个高层接口,这个接口值得这一子系统更加容易使用,需要的朋友可以参考下2015-03-03
最新评论