\r\n\r\n嘿嘿,看见没有,它要求的参数必须是数字,这样我们的目的就达到了,同样的写法:\r\n
/**\r\n * 是否为数字\r\n * @param {Object}\r\n * @return {Boolean}\r\n */\r\nisNumber : function(o){\r\n\treturn !isNaN(o);\r\n}\r\n","post_title":"javascript判断是否为数字干练的方法","post_excerpt":"javascript判断是否为数字最好、最干练的方法就用javascript内置的方法。","post_name":"javascript_isfinite","post_modified_gmt":"2013-06-07T22:51:20.000Z"},{"ID":229,"post_content":"javascript开发中经常遇到要去判断对象的的类型,对于Function、String、 Number、Undefined 等几种类型的对象来说一般的应用上就足够了,但是如果要来判断对象是不是正则那就要自己封装了,javascript没有提供判断正则对象的方法。\r\n
/**\r\n * 是否为正则对象\r\n * @param {Object}\r\n * @return {Boolean}\r\n */\r\nisRegExp : function(o){\r\n\treturn o && Object.prototype.toString.call(o) === '[object RegExp]';\r\n}\r\n原理是将正则对象转化整字符串,看它是不是[object RegExp]就可以了。","post_title":"javascript判断是否为为正则对象","post_excerpt":"如果要你来判断javascript是否为为正则对象,你会怎么做?javascript没有提供判断正则对象的方法,当然是自己封装一个。","post_name":"javascript_isregexp","post_modified_gmt":"2013-06-07T22:39:24.000Z"},{"ID":227,"post_content":"html5提供了placeholder让前端开发人员省了不少事,但是如果你要设置的颜色就有点蛋疼了,css没直接提供这样的选择器,毕竟placeholder是后来者,那怎么办呢?能不能修改?答案是可以了,css没有提供,我们可爱的现代浏览器有提供,嘿嘿~~~收藏吧童鞋们~~~\r\n
::-webkit-input-placeholder { /* WebKit browsers */\r\n color: #999;\r\n}\r\n:-moz-placeholder { /* Mozilla Firefox 4 to 18 */\r\n color: #999;\r\n}\r\n::-moz-placeholder { /* Mozilla Firefox 19+ */\r\n color: #999;\r\n}\r\n:-ms-input-placeholder { /* Internet Explorer 10+ */\r\n color: #999;\r\n}","post_title":"给input的placeholder设置颜色","post_excerpt":"placeholder要设置的颜色就有点蛋疼了,css没直接提供这样的选择器,毕竟placeholder是后来者,那怎么办呢?","post_name":"input-placeholder-color","post_modified_gmt":"2013-06-06T22:48:30.000Z"},{"ID":226,"post_content":"坑爹的with,貌似很多大神都建议不要用它,因为它会增加with 语句以外的数据的访问代价。但是说归说,遇到了就算给你自己增加知识点,现在给大家弄一道群的同学提供的with语句面试题:\r\n
({\r\n\tx : 10,\r\n\tfoo : function () {\r\n\t\tfunction bar() {\r\n\t\t\tconsole.log(x);\r\n\t\t\tconsole.log(y);\r\n\t\t\tconsole.log(this.x);\r\n\t\t}\r\n\t\twith (this) {\r\n\t\t\tvar x = 20;\r\n\t\t\tvar y = 30;\r\n\t\t\tbar.call(this);\r\n\t\t}\r\n\t}\r\n}).foo();\r\n请问上面这段代码输入了什么?答案是:\r\n
undefined\r\n30\r\n20\r\n你对了吗?其中 ({}).foo() 这样执行的时候,this 指向的是那个 {} 对象,所以如果我们去输入this时会输出:\r\n
Object {x: 10, foo: function}\r\n进入到 with 里面的时候,var x = 20; 查找的时候,会发现 this.x 是存在的,所以忽略了那个 var。直接把 this.x 赋值为 20了,var y = 30; 由于 this 没有 y 属性,所以就声明了一个变量y,在 with 的闭包里面。然后执行 bar 的时候,先找 x,由于 x 之前没声明过,所以,x 就是 undefined,最后 this.x ,这个就是 20 了","post_title":"javascript的with语句面试题","post_excerpt":"坑爹的with,貌似很多大神都建议不要用它,因为它会增加with 语句以外的数据的访问代价。但是说归说,遇到了就算给你自己增加知识点。","post_name":"javascript_with","post_modified_gmt":"2013-06-06T22:48:59.000Z"},{"ID":225,"post_content":"在ie9以下的版本,空的src会造成重复请求,当然如果你只需要兼容现代浏览器就可以忽略这个问题,img空的src什么情况呢?\r\n\r\n在ie9以下下,如果你这样写:\r\n\r\n<img src=\"\" />\r\n\r\n恭喜你中奖了,如果你查看你的服务器日志,你会发现日志中会有一种莫名的请求。当你这样写时:\r\n
<img />\r\n这样反而一切正常,空src解析成当前的url,既然没有src,空Img不会有后遗证,那我们在做图片按需加载时,就有把src换成其他的写法:\r\n
<img data-lazyload-src=\"http://zkeyword.com/wp-content/themes/zkeyword/images/logo.png\" width=\"207\" height=\"26\">\r\n这样的兼容性问题还真的是不好解决,ie下要安装什么调试软件还真是不容易,特别是ie低版本,前端监控,建议你可以使用Fiddler。","post_title":"ie下img最好别出现src为空的情况","post_excerpt":"在ie9以下的版本,空的src会造成重复请求,如果你查看你的服务器日志,你会发现日志中会有一种莫名的请求。","post_name":"ie_img_src_empty","post_modified_gmt":"2013-06-03T21:58:24.000Z"},{"ID":223,"post_content":"所谓静态资源是指web应用中的css、js、图片等资源,浏览器在加载网页中包含的各个资源时,先会判断缓存中是否已经包含了静态资源,如果包含,就不去服务器获取了。\r\n\r\n比如说,我们修改wordpress中的style.css文件,那么,浏览器会“自作聪明”的地使用缓存中的版本,那么我们就看不到我们想要的结果,相信制作页面的前端同学应该有遇到这样的问题吧。\r\n\r\n现在网上对于这个问题也有相对应的解决方法:让浏览器认为我们修改过的静态资源新的,重新缓存这个文件,一般我们只需要在调用的url加入版本号即可,比如:“style.css?v=yyyymmdd”,虽然定位到的资源仍然是style.css,但如果v的值不同,浏览器会认为是不同的资源。同理,对于js、图片来说,也是如此。\r\n\r\n那么,讲了这么多,我们就来实现这样的功能,先实现style.css ,只要在functions.php加入下面代码:\r\n
function cache_style($stylesheet_uri){\r\n $arr = explode('wp-content', $stylesheet_uri);\r\n $stylesheet_uri = $stylesheet_uri . '?v=' . filemtime(ABSPATH . '/wp-content' . $arr[1]);\r\n return $stylesheet_uri;\r\n}\r\nadd_filter('stylesheet_uri','cache_style',9999,1);\r\n就这样,我们就在style.css加入了版本号,这段代码的原理是,利用php中的filemtime()函数读取style.css的修改时间,然后通过add_filter钩子重写stylesheet_uri,嘿嘿不难吧,如果还要再细一点,可以将filemtime()用data()格式化成日期。\r\n\r\n而js怎么办呢?我们的js没有类似于stylesheet_uri的东西,原理当然也是利用filemtime(),照样实现照样的功能:\r\n
<?php echo '?v=' . filemtime( ABSPATH.'js放置的位置' ); ?>\r\n其中,ABSPATH是php中的绝对地址,当然如果你不想代码看起来太杂,那么你可以尝试着将上面的代码封装起来,这里就不再深入了。同理,图片来说,也是如此,大家可以试试。","post_title":"给wordpress的静态资源加上时间戳","post_excerpt":"我们修改wordpress中的style.css文件,那么,浏览器会“自作聪明”的地使用缓存中的版本,那么我们就看不到我们想要的结果,相信制作页面的前端同学应该有遇到这样的问题吧。","post_name":"wordpress_filemtime","post_modified_gmt":"2013-08-16T05:52:51.000Z"},{"ID":222,"post_content":"做为前端屌丝,最看不过去的代码也就是乱七八糟且又麻烦的代码,网上找到的随机文章代码要么是插件,要嘛是sql查询,一个随机文章搞那么麻烦干啥,下面是我用过的,大家可以将代码贴到你想调用随机文章的地方,css在自己写下。\r\n
<ul class=\"randomList\">\r\n<?php\r\nglobal $post;\r\n$rand_posts = get_posts('numberposts=8&category=&orderby=rand');\r\nforeach($rand_posts as $post){?>\r\n\t<li><a href=\"<?php the_permalink(); ?>\" title=\"<?php the_title(); ?>\"><?php echo mb_strimwidth(get_the_title(), 0,34, '...'); ?></a></li>\r\n<?php };?>\r\n</ul>","post_title":"wordpress免插件随机文章","post_excerpt":"wordpress随机文章,免插件的哦,实用又简单~~~","post_name":"wordpress_randoml_post","post_modified_gmt":"2013-08-16T05:52:51.000Z"},{"ID":221,"post_content":"在一个字符串中替换多个字符怎么做,用正则吗?当然用,但是光正则不行还要再处理一下,将替换字符的动作封装成函数,要用的时候就很方便了:\r\n
/** \r\n * 对一个字符串进行多次replace\r\n * @method mulReplace\r\n * @static\r\n * @param {String} s 需要处理的字符串\r\n * @param {array} arr 数组,每一个元素都是由replace两个参数组成的数组\r\n * @return {String} 返回处理后的字符串\r\n */\r\nmulReplace: function(s, arr) {\r\n\tfor (var i = 0; i < arr.length; i++) {\r\n\t\ts = s.replace(arr[i][0], arr[i][1]);\r\n\t}\r\n\treturn s;\r\n}\r\n调用时:\r\n
alert( mulReplace(\"I like aa and bb. he likes aa.\",[[/aa/g,\"山\"],[/bb/g,\"水\"]]) );","post_title":"对一个字符串进行多次replace","post_excerpt":"在一个字符串中替换多个字符怎么做,用正则吗?","post_name":"multi-replace","post_modified_gmt":"2013-06-02T17:07:33.000Z"},{"ID":220,"post_content":"相信有很多人都觉得wordpress的编辑器很好用,写作的时候会自动在换行的时候加入p标签,同时也不会产生太多余的代码,但是如果调用文章的内容来做描述也会自动加上p标签,如果根据不同需求这样貌似不是很好,只要将下面代码加入functions.php就可以了:\r\n
function deletehtml($description) {\r\n\t$description = trim($description);\r\n\t$description = strip_tags($description,\"\");\r\n\treturn ($description);\r\n}\r\nadd_filter('category_description', 'deletehtml');","post_title":"wordpress移除描述P标签","post_excerpt":"wordpress可以直接引用文章来当描述,但是有时候引用其内容会直接把p标签给带过来,怎么去掉呢?","post_name":"wordpress-description-deleteh-p","post_modified_gmt":"2013-08-16T05:52:51.000Z"},{"ID":218,"post_content":"图片上传预览是一种在图片上传之前对图片进行本地预览的技术,但是一般要先上传到服务器才能预览,但为了提高用户体验,网上已经有很多变通或先进的方法来实现。\r\n\r\n其中原理的,在ie用将上传图转成filter滤镜的方式的预览图,而chrome、firefox等现代浏览器则是通过base64编码实现,下面代码共享给大家有兴趣的可以玩玩。\r\n\r\nhtml代码:\r\n
<div id=\"preview\"></div>\r\n<input type=\"file\" onchange=\"previewImage(this)\" id=\"f\" />\r\ncss代码:\r\n
*{ margin: 0px; padding: 0px; }\r\n#preview{ height: 100px; border:1px solid #000;}\r\n#imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}\r\njs代码:\r\n
function previewImage(file) {\r\n\tvar MAXWIDTH = 100,\r\n\tMAXHEIGHT = 100,\r\n\tdiv = document.getElementById('preview');\r\n\r\n\tif (file.files & amp; & amp; file.files[0]) {\r\n\t\tvar reader = new FileReader();\r\n\r\n\t\treader.onload = function (e) {\r\n\t\t\tvar img = '<img src=\"' + e.target.result + '\" onload=\"fixImage( this, 100, 100 );\" />';\r\n\t\t\tdiv.innerHTML += img;\r\n\t\t}\r\n\r\n\t\treader.readAsDataURL(file.files[0]);\r\n\t} else {\r\n\t\tvar sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\"';\r\n\t\tfile.select();\r\n\t\tfile.blur();\r\n\t\tvar src = document.selection.createRange().text;\r\n\t\tsFilter += src + '\\\")';\r\n\r\n\t\tdiv.innerHTML += \"<div style='width:100px; height: 100px; float:left;\" + sFilter + \"'></div>\";\r\n\r\n\t}\r\n}\r\n\r\n//功能:等比例压缩图片,当图片较小时,垂直居中\r\nfunction fixImage(img, w, h) {\r\n\tvar newImg = new Image(); //获得图片的原始尺寸\r\n\tnewImg.src = img.src;\r\n\r\n\tvar lh; //用于保存img.height,IE下隐藏的图片读取不到,需currentStyle解决\r\n\r\n\tif (newImg.width / newImg.height & gt; = w / h) {\r\n\t\tif (newImg.width & gt; w) {\r\n\t\t\timg.width = w;\r\n\t\t\timg.height = w * newImg.height / newImg.width;\r\n\t\t\tlh = window.ActiveXObject ? parseInt(img.currentStyle['height']) : img.height;\r\n\t\t\timg.style.marginTop = (h - lh) / 2 + 'px'; //顺手垂直居中\r\n\t\t} else {\r\n\t\t\timg.width = newImg.width;\r\n\t\t\timg.height = newImg.height;\r\n\t\t\tlh = window.ActiveXObject ? parseInt(img.currentStyle['height']) : img.height;\r\n\t\t\timg.style.marginTop = (h - lh) / 2 + 'px'; //顺手垂直居中\r\n\t\t}\r\n\t} else {\r\n\t\tif (newImg.height & gt; h) {\r\n\t\t\timg.height = h;\r\n\t\t\timg.width = newImg.width * h / newImg.height;\r\n\t\t} else {\r\n\t\t\timg.width = newImg.width;\r\n\t\t\timg.height = newImg.height;\r\n\t\t}\r\n\t}\r\n}","post_title":"纯javascript图片上传预览","post_excerpt":"图片一般要先上传到服务器才能预览,但为了提高用户体验,网上已经有很多变通或先进的方法来实现,亲,你有兴趣吗,有兴趣就过来看看","post_name":"js_img_preview","post_modified_gmt":"2013-05-31T07:04:00.000Z"}],"pageIndex":6,"pageSize":10,"total":140}}