//StyleSheet Object
function StyleSheet(doc){
this.sso = null;
this.doc = doc;
this.createStyleSheet();
}
StyleSheet.prototype.createStyleSheet = function (){
//IE
if(this.doc.createStyleSheet)
this.sso = this.doc.createStyleSheet();
else{//FF
var styles = this.doc.getElementsByTagName("HEAD")[0].getElementsByTagName("style");
if(styles.length > 0)
this.sso = styles[styles.length-1];
else{
try{
this.sso=this.doc.createElement("STYLE");
this.sso.type="text/css";
this.doc.getElementsByTagName("HEAD")[0].appendChild(this.sso);
}catch(e){
this.sso = null;
}
}
}
}
StyleSheet.prototype.insertRule = function (selector,cssText){
if(this.sso.addRule)
this.sso.addRule(selector,cssText,this.sso.rules.length);
else if(this.sso.sheet)
this.sso.sheet.insertRule(selector + "{" + cssText + "}",this.sso.sheet.cssRules.length);
}
var ss = new StyleSheet(document);
ss.insertRule("#comfrm"+ this.unique,cssText);
function StyleSheet(doc){
this.sso = null;
this.doc = doc;
this.createStyleSheet();
}
StyleSheet.prototype.createStyleSheet = function (){
//IE
if(this.doc.createStyleSheet)
this.sso = this.doc.createStyleSheet();
else{//FF
var styles = this.doc.getElementsByTagName("HEAD")[0].getElementsByTagName("style");
if(styles.length > 0)
this.sso = styles[styles.length-1];
else{
try{
this.sso=this.doc.createElement("STYLE");
this.sso.type="text/css";
this.doc.getElementsByTagName("HEAD")[0].appendChild(this.sso);
}catch(e){
this.sso = null;
}
}
}
}
StyleSheet.prototype.insertRule = function (selector,cssText){
if(this.sso.addRule)
this.sso.addRule(selector,cssText,this.sso.rules.length);
else if(this.sso.sheet)
this.sso.sheet.insertRule(selector + "{" + cssText + "}",this.sso.sheet.cssRules.length);
}
var ss = new StyleSheet(document);
ss.insertRule("#comfrm"+ this.unique,cssText);
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="样式.aspx.cs" Inherits="样式" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.table
{
background:#59CBF5
}
</style>
<script type="text/javascript">
function change()
{
var aa = document.getElementById("text").className="table";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="text" onclick="change()"><tr><td>请点击</td></tr></table>
</div>
</form>
</body>
</html>