【例3-1】文字与背景颜色搭配。
<Html>
<Head><Title>文字与背景颜色搭配示例</Title>
<Script Language="VBScript">
<!--
Sub bchange(choice)
If choice=1 Then
document.bgcolor="red"
ElseIf choice=2 Then
document.fgcolor="blue"
ElseIf choice=3 Then
document.bgcolor="pink"
ElseIf choice=4 Then
document.fgcolor="yellow"
ElseIf choice=5 Then
document.bgcolor="white"
Else
document.fgcolor="black"
End If
End Sub
-->
</Script>
</Head>
<Body>
<Center><H2><Font Color="blue">文字与背景颜色搭配示例</Font></H2>
<Table border=3>
<Tr>
<Th>背景颜色<Th>选择<Th>文字颜色<Th>选择
</Tr>
<Tr>
<Td>红色</Td>
<Td>
<Input name="w" type="radio" onclick="bchange(1)">
<Td>蓝色</Td>
<Td>
<Input name="b" type="radio" onclick="bchange(2)">
</Tr>
<Tr>
<Td>粉红色</Td>
<Td>
<Input name="w" type="radio" onclick="bchange(3)">
</Td>
<Td>黄色</Td>
<Td>
<Input name="b" type="radio" onclick="bchange(4)">
</Td>
</Tr>
<Tr>
<Td>白色
<Td>
<Input name="w" type="radio" onclick="bchange(5)">
</Td>
<Td>黑色</Td>
<Input name="b" type="radio" onclick="bchange(6)">
</Td>
</Tr>
</Table>
</Center>
</Body>
</Html>
4.事件驱动示例这里介绍一个有关事件驱动的示例,程序名为drive.htm,代码如下:
<html>
<head>
<title>一个JavaScript的测试程序</title>
<script language="JavaScript">
<!--
function kkk(){
do{
username=prompt("请问您是谁","");
}while(username=="")
document.write(username,"请多多关照!");
}
-->
</script>
</head>
<body>
<input type="button" value="你敢碰我吗?" name=button1 onClick="kkk()">
</body>
</html>