• JS 根据屏幕大小以及浏览器加载不同 CSS 样式

    4年前零度温柔95571Javascript & jQuery

    闲来没事写个 CSS hack。    


    window.onload = loadStyleFun();
    
    function loadStyleFun(){
    	var _lQ = window.navigator.userAgent;
    
    	if ( _lQ.indexOf("MSIE") >= 0 ){
    		var _IE_1024 = "IE_1024.css";
    		var _IE_1280 = "IE_1280.css";
    		checkScreenSize( _IE_1024, _IE_1280 );
    	}else if( ( _lQ.indexOf("Chrome") >= 0 ) || ( _lQ.indexOf("Firefox") >= 0 ) ){
    		var _Other_1024 = "FF_GG_1024.css";
    		var _Other_1280 = "FF_GG_1280.css";
    		checkScreenSize( _Other_1024, _Other_1280 );
    	}else{
    		var _Other_1024 = "other_1024.css";
    		var _Other_1280 = "other_1280.css";
    		checkScreenSize( _Other_1024, _Other_1280 );
    	}
    }
    
    function checkScreenSize( CSS_1024, CSS_1280 ){
    	var _width = document.documentElement.clientWidth;
    	if ( _width < 1280 ){
    		setActiveStyleSheet( CSS_1024 );
    	}else{
    		setActiveStyleSheet( CSS_1280 );
    	}
    }
    
    function setActiveStyleSheet( css ){
    	document.getElementsByTagName("link")[0].href = "./style/" + css;
    }


    兼容 屏幕大小 浏览器  
    15
  • jQuery Table tr 隔行换色小插件

    6年前零度温柔33611Javascript & jQuery

     (function($){
         $.fn.extend({
         "SetTableBgColor" : function(options){
             option = $.extend({
                 Odd : "Odd", //奇数
                 Even : "Even", //偶数
                 Selected : "Selected", //选中
                 Over : "Over" //鼠标移上去
             },options);  //此处options与function里的参数为同一个对象
             //隔行换色
             $("tbody > tr:even", this).addClass(option.Even);
             $("tbody > tr:odd", this).addClass(option.Odd);
             //鼠标移上去
             $("tbody > tr", this).mouseover(function(){
                 if ($(this).hasClass(option.Selected) == false){
                     $(this).addClass(option.Over);
                 }
             });
             //鼠标移出
             $("tbody > tr", this).mouseout(function(){
                 $(this).removeClass(option.Over);
             });
             //单击变色
             $("tbody > tr", this).click(function(){
                 $("tbody > tr").removeClass(option.Over);
                 if ($(this).hasClass(option.Selected) == false){
                     $(this).addClass(option.Selected);
                 }else{
                     $(this).removeClass(option.Selected);
                 }
             });
        
           
    jQuery 隔行换色  
    22
  • 关于table tr 隔行换色的JS代码

    6年前零度温柔28060Javascript & jQuery

    function senfe(o, a, b, c, d) {
    	var t = document.getElementById(o).getElementsByTagName("tr");
    	for ( var i = 0; i < t.length; i++) {
    		t[i].style.backgroundColor = (t[i].sectionRowIndex % 2 == 0) ? a : b;
    		t[i].onclick = function() {
    			if (this.x != "1") {
    				this.x = "1";// 本来打算直接用背景色判断,FF获取到的背景是RGB值,不好判断
    				this.style.backgroundColor = d;
    			} else {
    				this.x = "0";
    				this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a : b;
    			}
    		}
    		t[i].onmouseover = function() {
    			if (this.x != "1"){
    				this.style.backgroundColor = c;
    			}
    		}
    		t[i].onmouseout = function() {
    			if (this.x != "1"){
    				this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a:b;
    			}
    		}
    	}
    }
    //senfe("table ID","奇数行背景","偶数行背景","鼠标经过背景","点击后背景"); 
    senfe("senfe","#fff","#F3F8F7","#CFC","#CF9"); 
    
    18
3条记录1/1 页