This file contains 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
50个比较实用jQuery代码段 | |
http://bbs.html5cn.org/forum.php?mod=viewthread&tid=2934&extra= | |
本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助。 | |
其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助你又快又好地把事情完成。这些都是我尽量记住的有着最佳性能的代码段,因此如果你发现你任何可以做得更好的地方的话,欢迎把你的版本粘贴在评论中!我希望你在这一文章中能找到有帮助的东西。 | |
1. 如何创建嵌套的过滤器: | |
//允许你减少集合中的匹配元素的过滤器, |
This file contains 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
1.强制按照ie7的模式来渲染,无视doc头声明,和兼容性设置 | |
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> | |
2.强制按照ie当前版本来渲染,同上。 | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
3.直接跳转 | |
<meta http-equiv="refresh" content="0;url=pathtojump"/> | |
4.禁止网页在移动设备上的缩放(非强制禁止) |
This file contains 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
javascript中取模运算的结果有时候是很让人伤心的 | |
看下面的算式 | |
3%4==3 //true | |
2%4==2 //true | |
1%4==1 //true | |
0%4==0 //true | |
-1%4==3 //false | |
. | |
. |
This file contains 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
/** | |
* 取模运算 | |
* @param be_mod a%b 中的a | |
* @param mod a%b 中的b | |
* @returns {number} 计算结果 | |
*/ | |
function modp(be_mod,mod){ | |
return be_mod>=0?(be_mod % mod):(((be_mod%mod)+mod)%mod); | |
} |
This file contains 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
Apache或者xmapp配置域名并跳转到特定目录 | |
1.在/conf/extra/httpd-vhosts.conf中(或者直接写到httpd.conf)增加 | |
<VirtualHost *:80> | |
DocumentRoot "E:/http/sanyou_cc" | |
ServerName "sanyou.cc" | |
</VirtualHost> | |
可以参考42行之前的举例,这里需要注意的是,apache的配置,不能用tab,不然会报错 | |
如果端口好不为80可以在httpd.conf中增加 | |
Listen 80 |
This file contains 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
//1窗口滚动到某位置的js | |
window.onscroll = document.body.onscroll = function(){ | |
var val = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | |
console.log(val); | |
} |
This file contains 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
/** | |
* 获取某对象,对应深度的值 | |
* var data = { | |
* "level_1":{ | |
* "level_2":"value" | |
* } | |
* } | |
* subfield(data,"level_1.level_2") //"value" | |
*/ | |
function subfield(data,f){ |
This file contains 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
/** | |
* 根据某目录名分割路径 | |
* ex:split_path | |
* @param path 要切割的路径 | |
* @param str1 按照可能存在的目录顺序传入参数 | |
* @param strn | |
* @param ... | |
*/ | |
function split_path(path,str1,strn){ | |
var ret,str, strlist = Array.prototype.slice.call(arguments,1); |
This file contains 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
/* | |
* @function: 通过a标签解析url标签 | |
* @param:url url参数是字符串,解析的目标 | |
通过IE6-9 chrome Firefox测试 | |
* | |
*/ | |
function parseURL(url) { | |
//创建一个a标签 | |
var ac = arguments.callee; |
This file contains 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
/** | |
* 获取当前页面的目录 | |
* "http://aa/b/s/b.html" //"http://aa/b/s/" | |
* "http://aa/b/s/b.html/#a/b/c" //"http://aa/b/s/" | |
* "http://aa/b/s/b.html/?asdf=p&a=s#a/b/c" //"http://aa/b/s/" | |
**/ | |
location.href.replace(/([^#?]+)\/.*?$/,"$1/") |
OlderNewer