function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img/>')[0].src = this;
// Alternatively you could use:
// (new Image()).src = this;
});
}
// 用法:
preload([
'img/imageName.jpg',
'img/anotherOne.jpg',
'img/blahblahblah.jpg'
]);
或者使用jQuery的preload插件:
jQuery.isNumeric(value);
或
function isNumeric(obj) {
return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
}
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex ;// While there remain elements to shuffle...
while (0 !== currentIndex) {// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
$.getScript("my_lovely_script.js", function(){
alert("Script loaded and executed.");
// Use anything defined in the loaded script...
});
不使用jQuery的方法请参考:http://stackoverflow.com/questions/950087/include-a-javascript-file-in-another-javascript-file
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
// 类似于HTTP跳转
window.location.replace("
http://howto.eguidedog.net");
// 类似于点击一个链接
window.location.href = "
http://howto.eguidedog.net";
有时候,我们想通过Javascript/jQuery获取URL中的参数值,例如想获取下面地址中的q值(keyword):
http://example.com/?q=keyword&action=query
可以通过下面函数实现:
热门内容
最新内容
- 1 day 12 hours ago
- 4 days 15 hours ago
- 5 days 13 hours ago
- 1 week 5 days ago
- 2 weeks 1 day ago
- 2 weeks 1 day ago
- 2 weeks 1 day ago
- 2 weeks 1 day ago
- 2 weeks 2 days ago
- 1 month ago
最新评论