
本文实例总结了经典且实用的jQuery代码开发技巧。分享给大家供大家参考。具体如下:
23. jQuery延时加载功能
Want to delay something?
$(document).ready(function() {
window.setTimeout(function() {
// do something
}, 1000);
});
24. 移除单词功能
Want to remove a certain word(s)?
$(document).ready(function() {
var el = $(#id);
el.html(el.html().replace(/word/ig, “”));
});
25. 验证元素是否存在于jquery对象集合中
Simply test with the .length property if the element exists.
$(document).ready(function() {
if ($(#id).length) {
// do something
}
});
26. 使整个DIV可点击
Want to make the complete div clickable?
$(document).ready(function() {
$(“div”).click(function(){
//get the url from href attribute and launch the url
window.location=$(this).find(“a”).attr(“href”); return false;
});
// how to use