透過JavaScript更改style的class屬性範例

  • 16989
  • 0
  • ASP
  • 2008-08-28

摘要:透過JavaScript更改style的class屬性範例

已經定義好的style,如果想更改內容的話,應該如何做呢
以下是個簡單的範例
 


 

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<style id=wstyle>
.txt1{background-Color:skyblue}
</style>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function button1_onclick() {
//window.alert(window.document.styleSheets[0].rules('txt1').style.backgroundColor);
//window.document.styleSheets[0].rules('txt1').style.backgroundColor='yellow';
//經測試用名稱好像會有問題,用index可以
window.document.styleSheets[0].rules(0).style.backgroundColor='yellow';
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<%for y = 1 to 10%>
<INPUT type="text" id=text1 name=text1 class=txt1><br>
<%Next%>
<INPUT type="button" value="Button" id=button1 name=button1 LANGUAGE=javascript onclick="return button1_onclick()">
</FORM>
</BODY>
</HTML>

以下是簽名:


Microsoft MVP
Visual Studio and Development Technologies
(2005~2019/6) 
topcat
Blog:http://www.dotblogs.com.tw/topcat