参考:
var json_text = JSON.stringify(your_object);
var your_object = JSON.parse(json_text);
参考:http://stackoverflow.com/questions/191881/serializing-to-json-in-jquery
为了保证参数值特殊字符被转义,应该使用encodeURIComponent编码URL参数值
var myOtherUrl = "http://example.com/index.html?url=" + encodeURIComponent(myUrl);
<!-- load jQuery 1.1.3 -->
<script type="text/javascript" src="http://example.com/jquery-1.1.3.js"></script>
<script type="text/javascript">
var jQuery_1_1_3 = $.noConflict(true);
</script>
<!-- load jQuery 1.3.2 -->
<script type="text/javascript" src="http://example.com/jquery-1.3.2.js"></script>
<script type="text/javascript">
var jQuery_1_3_2 = $.noConflict(true);
</script>
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插件:
$.fn.preload = function() {
this.each(function(){
$('<img/>')[0].src = this;
});
}
// 用法:
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;// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}return array;
}
$.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
热门内容
最新内容
- 9 小时 ago
- 17 小时 ago
- 1 天 10 小时 ago
- 2 天 16 小时 ago
- 2 天 16 小时 ago
- 2 天 16 小时 ago
- 3 天 10 小时 ago
- 6 天 8 小时 ago
- 6 天 14 小时 ago
- 1 周 ago
最新评论