⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例4-30.htm

📁 web课件并附有习题练习还有实例详细的讲解了WEB的各种开发过程是学习 的好资料
💻 HTM
字号:
<html><head><title>StyleShees数组和StyleSheet对象</title>
<style type="text/css">
<!--
p {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 36px;
	color: #0000FF;
	background-color: #FFCC00;
}
-->
</style>

<script language=VBScript>
Dim index,SetBg,SetFont,SetBgIndex,SetFontIndex,DelBg,DelFont
index=0  			'样式表索引
SetBg=false    		'是否已添加背景样式
SetFont=false  		'是否已添加字体样式
SetBgIndex=0   	'背景样式索引
SetFontIndex=0   	'字体样式索引
DelBg=true    		'背景样式是否不存在
DelFont=true    	'字体样式是否不存在
Sub AddRulesToStylesheet(WhichStyle,Rules)
    Document.StyleSheets(0).addRule WhichStyle,Rules
End Sub
Sub SetBg_onClick( )
    If SetBg Then
      alert "已经设置了cyan背景样式,不能再进行设置!"
      Exit Sub
    Else
      call AddRulesToStylesheet("p","background-color:cyan")
      SetBg=true : DelBg=false : index=index+1 
      SetBgIndex=index
    End If
  End Sub
  Sub SetFont_onClick( )
    If SetFont Then
      alert "已经设置了隶书字体样式,不能再进行设置!"
      Exit Sub
    Else
      call AddRulesToStylesheet("p","font-family:'隶书'")
      SetFont=True : DelFont=false : index=index+1
      SetFontIndex=index
    End If
  End Sub
  Sub DelBg_onClick( )
    If DelBg Then
      alert "尚未设置cyan背景样式,不能清除!"
      Exit Sub
    Else
      Document.StyleSheets(0).RemoveRule SetBgIndex
      DelBg=true : SetBg=false : index=index-1 : SetBgIndex=0
    End If
  End Sub
  Sub DelFont_onClick( )
    If DelFont Then
      alert "尚未设置隶书字体样式,不能清除!"
      Exit Sub
    Else
      Document.StyleSheets(0).RemoveRule SetFontIndex
      DelFont=true : SetFont=false : index=index-1 : SetFontIndex=0
  End If
End Sub
</script></head>
<body topmargin=20><center><h1>利用StyleSheet对象改变文字的样式设置</h1>
</center><hr>按下按钮就可进行相应的样式设置:<br><br>
<form><center>
<input type=button id=SetBg value="设置下列文字段的背景色为cyan">
<input type=button id=SetFont value="设置下列文字段的字体为隶书">
<br><br></center>
按下按钮就可清除相应的样式设置:<br><br>
<center><input type=button id=DelBg value="清除下列文字段的cyan背景色设置">
<input type=button id=DelFont value="清除下列文字段的隶书字体设置"></center>
</form><br><center>
<p>白日依山尽<br>黄河入海流<br>欲穷千里目<br>
更上一层楼</p>
<p>sdjkf;asdkljflasdfasdl;fasd
asgfasdkfj;asdkljl;gf
d
</p></center>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -