01.var addSheet = function(){
02. var doc,cssCode;
03. if(arguments.length == 1){
04. doc = document;
05. cssCode = arguments[0]
06. }else if(arguments.length == 2){
07. doc = arguments[0];
08. cssCode = arguments[1];
09. }else{
10. alert("addSheet函数最多接受两个参数!");
11. }
12. if(!+"\v1"){//增加自动转换透明度功能,用户只需输入W3C的透明样式,它会自动转换成IE的透明滤镜
13. var t = cssCode.match(/opacity:(\d?\.\d+);/);
14. if(t!= null){
15. cssCode = cssCode.replace(t[0], "filter:alpha(opacity="+ parseFloat(t[1]) * 100+")")
16. }
17. }
18. cssCode = cssCode + "\n";//增加末尾的换行符,方便在firebug下的查看
19. var headElement = doc.getElementsByTagName("head")[0];
20. var styleElements = headElement.getElementsByTagName("style");
21. if(styleElements.length == 0){//如果不存在style元素则创建
22. if(doc.createStyleSheet){//ie
23. doc.createStyleSheet();
24. }else{
25. var tempStyleElement = doc.createElement('style');//w3c
26. tempStyleElement.setAttribute("type", "text/css");
27. headElement.appendChild(tempStyleElement);
28. }
29. }
30. var styleElement = styleElements[0];
31. var media = styleElement.getAttribute("media");
32. if(media != null && !/screen/.test(media.toLowerCase()) ){
33. styleElement.setAttribute("media","screen");
34. }
35. if(styleElement.styleSheet){//ie
36. styleElement.styleSheet.cssText += cssCode;
37. }else if(doc.getBoxObjectFor){
38. styleElement.innerHTML += cssCode;//火狐支持直接innerHTML添加样式表字串
39. }else{
40. styleElement.appendChild(doc.createTextNode(cssCode))
41. }
42.}
1.var ddd = document.getElementById("ddd");
2.ddd.style.border = "1px solid red";
1.var ddd = document.getElementById("ddd");
2.ddd.style.cssText = "border:1px solid red;color:#000;background:#444;float:left";
01.function addSheetFile(path){
02. var fileref=document.createElement("link")
03. fileref.rel = "stylesheet";
04. fileref.type = "text/css";
05. fileref.href = path;
06. fileref.media="screen";
07. var headobj = document.getElementsByTagName('head')[0];
08. headobj.appendChild(fileref);
09.}
1.var oStylesheet = document.createStyleSheet ( sURL , iIndex );
1. var iframe = document.createElement('iframe');//生成用于编辑的rich text editor
2. var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
01.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
02."">
03.<html xmlns="" xml:lang="en" lang="en">
04. <head>
05. <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
06. <%# 强制IE8像IE7一样呈现网页 -%>
07. <meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE7″ />
08. <%#--默认所有的链接都在本窗口打开 -%>
09. <base target="_self" />
10. <title><%= h(yield(:title)) || controller.action_name%></title>
11. <%= stylesheet_link_tag "screen","button","style"%>
12. <link rel="stylesheet" href="/stylesheets/print.css" type="text/css" media="print">
13. <!--[if lt IE 8]>
14. <link rel="stylesheet" href="/stylesheets/ie.css" type="text/css" media="screen">
15. <![endif]-->
16. <%= javascript_tag "window._token = '#{form_authenticity_token}'" if ActionController::Base.allow_forgery_protection%>
17. <%= javascript_include_tag :defaults%>
18. <style type="text/css" media="print"></style>
19. </head>
1.var styleElement = styleElements[0];
2.var media = styleElement.getAttribute("media");
3.if(media != null && !/screen/.test(media.toLowerCase())){
4. styleElement.setAttribute("media", "screen");
5.}
01.addSheet("\
02. .RTE_iframe{width:600px;height:300px;}\
03. .RTE_toolbar{width:600px;}\
04. .color_result{width:216px;}\
05. .color_view{width:110px;height:25px;}\
06. .color_code{text-align:center;font-weight:700;color:blue;font-size:16px;}\
07. div.table{width:176px;position:absolute;padding:1px;}\
08. div.table td{font-size:12px;color:red;text-align:center;}\
09." );*/
01./*
02.动态添加样式表的规则
03.*/
04.iCSS={add:function(css){
05. var D=document,$=D.createElement('style');
06. $.setAttribute("type","text/css");
07. $.styleSheet&&($.styleSheet.cssText=css)||
08. $.appendChild(D.createTextNode(css));
09. D.getElementsByTagName('head')[0].appendChild($);
10.}};
11.iCSS.add("\
12. .dhoooListBox,.dhoooListBox li{margin:0;padding:0;list-style-type:none;font-size:12px;cursor:default}\
13. .dhoooListBox{border:1px solid #aaa;width:180px;background:#eee;height:200px;overflow:auto;float:left}\
14. .dhoooListBox li{margin:5px;line-height:24px;background:url(images/smilies/time.gif) no-repeat 0 60%;padding-left:25px;color:#555;}\
15. .dhoooListBox li.selected{background-color:#FFCC33}\
16.");
01.var getClass = function(ele) {
02. return ele.className.replace(/\s+/,' ').split(' ');
03.};
04.var hasClass = function(ele,cls) {
05. return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
06.}
07.var addClass = function(ele,cls) {
08. if (!this.hasClass(ele,cls)) ele.className += " "+cls;
09.}
10.var removeClass = function(ele,cls) {
11. if (hasClass(ele,cls)) {
12. var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
13. ele.className=ele.className.replace(reg,' ');
14. }
15.}