This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 切换启用和禁用表单项 | |
| (function ($) { | |
| $.fn.toggleDisabled = function() { | |
| return this.each(function() { | |
| var $this = $(this); | |
| if ($this.attr('disabled')) $this.removeAttr('disabled'); | |
| else $this.attr('disabled', 'disabled'); | |
| }); | |
| }; | |
| })(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 预防对表单进行多次提交 | |
| $(function() { | |
| $('form').submit(function() { | |
| if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') { | |
| jQuery.data(this, "disabledOnSubmit", { submited: true }); | |
| $('input[type=submit], input[type=button]', this).each(function() { | |
| $(this).attr("disabled", "disabled"); | |
| }); | |
| return true; | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 在新窗口打开链接 | |
| $('a[rel='external']').click(function() { | |
| this.target = "_blank"; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 图片预加载 | |
| (function($) { | |
| var cache = []; | |
| // Arguments are image paths relative to the current page. | |
| $.preLoadImages = function() { | |
| var args_len = arguments.length; | |
| for (var i = args_len; i--;) { | |
| var cacheImage = document.createElement('img'); | |
| cacheImage.src = arguments[i]; | |
| cache.push(cacheImage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 获取 URL 中传递的参数 | |
| $.urlParam = function(name) { | |
| var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); | |
| if (!results) { return 0; } | |
| return results[1] || 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 禁用表单的回车键提交 | |
| $("#form").keypress(function(e) { | |
| if (e.which == 13) { | |
| return false; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* IE6+ 图片水平垂直居中 */ | |
| /* 优点:兼容性较好,算是比较完美的一个方法了。缺点:需要计算 font-size 会有略微误差。*/ | |
| .ie6-img { | |
| display: block; | |
| width: 200px; | |
| height: 200px; | |
| line-height: 146px; | |
| overflow: hidden; | |
| text-align: center; | |
| *font-size: 175px; /* 0.875 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** 只用 CSS 做到完全居中 **/ | |
| .absolute-center { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| bottom: 0; | |
| right: 0; | |
| width: 50%; | |
| height: 50%; | |
| /*overflow: auto;*/ |