pn = { version : '1.0' }; /** * get url parameter */ pn.getparam = function(key) { var params = location.search.substr(1).split('&'); var kv; for (var i = 0;i < params.length; i++) { kv = params[i].split('='); if (kv[0] == key) { return kv[1]; } } }; /** * check checkbox. * * @param name * string of checkbox name * @param checked * boolean of checked */ pn.checkbox = function(name, checked) { $("input[type=checkbox][name=" + name + "]").each(function() { $(this).prop("checked", checked); }); if(checked){ $("tbody tr").each(function(){ $(this).prop("bgcolor","#b8d8e2"); $(this).unbind(); }); }else{ $("tbody tr").each(function(){ $(this).prop("bgcolor","#dbedf4"); $(this).bind('mouseover', function() { $(this).prop("bgcolor","#b8d8e2"); }); $(this).bind('mouseout', function() { $(this).prop("bgcolor","#dbedf4"); }); }); } } pn.selectcheckbox = function(value, checked) { var checkbox=$("input[type=checkbox][value=" + value + "]"); var tr=checkbox.parent().parent(); checkbox.prop("checked", checked); if(checked){ tr.prop("bgcolor","#b8d8e2"); tr.unbind("mouseout"); tr.unbind("mouseover"); }else{ tr.prop("bgcolor","#dbedf4"); tr.bind('mouseout', function() { tr.prop("bgcolor","#dbedf4"); }); tr.bind('mouseover', function() { tr.attr("bgcolor","#b8d8e2"); }); } } /** * 复选框选中的个数 * * @param name * string of checkbox name */ pn.checkedcount = function(name) { var batchchecks = document.getelementsbyname(name); var count = 0; for (var i = 0;i < batchchecks.length; i++) { if (batchchecks[i].checked) { count++; } } return count; } /** * 颜色选择器 */ pn.colorpicker = function(input) { var obj = this; this.isshow = false; this.target = $(input); this.button = $(""); this.target.after(this.button); this.over = function() { $(this).css("border", "1px solid #000"); } this.out = function() { $(this).css("border", "1px solid #fff"); } //title获取不到改成获取id属性 this.click = function() { var color = $(this).attr("id"); obj.setcolor(color); this.isshow = false; obj.picker.hide(); } this.createpicker = function() { var c = ["#ff8080", "#ffff80", "#80ff80", "#00ff80", "#80ffff", "#0080ff", "#ff80c0", "#ff80ff", "#ff0000", "#ffff00", "#80ff00", "#00ff40", "#00ffff", "#0080c0", "#8080c0", "#ff00ff", "#804040", "#ff8040", "#00ff00", "#008080", "#004080", "#8080ff", "#800040", "#ff0080", "#800000", "#ff8000", "#008000", "#008040", "#0000ff", "#0000a0", "#800080", "#8000ff", "#400000", "#804000", "#004000", "#004040", "#000080", "#000040", "#400040", "#400080", "#000000", "#808000", "#808040", "#808080", "#408080", "#c0c0c0", "#400040", "#ffffff"]; var s = "" + ""; // 列数 var col = 8; for (var i = 0, len = c.length;i < len; i++) { /* s += ""; */ s += ""; if ((i + 1) != c.length && (i + 1) % col == 0) { s += ""; } } // s += ""; s += "
 
 
clear
"; var picker = $(s); picker.find(".c").each(function() { $(this).bind("mouseover", obj.over); $(this).bind("mouseout", obj.out); $(this).bind("click", obj.click); }); $(document.body).append(picker); return picker; } this.setcolor = function(color) { obj.target.val(color); if (color == "") { color = "#fff"; } try { obj.button.css( { backgroundcolor : color }); } catch (e) { alert("color error: " + color); obj.target.focus().select(); } } this.picker = this.createpicker(); this.showpicker = function() { if (!obj.isshow) { obj.isshow = true; obj.picker.showby(obj.target); $(document).bind("mousedown", function() { $(document).unbind("mousedown"); settimeout(function() { obj.isshow = false; obj.picker.hide(); var val = obj.target.val(); obj.setcolor(obj.target.val()); }, 200); }); } } this.button.bind("click", obj.showpicker); this.target.bind("blur", function() { obj.setcolor(obj.target.val()); }); var v = this.target.val(); if (v != "") { this.setcolor(v); } }; $.fn.extend( { colorpicker : function() { new pn.colorpicker(this); } });