jquery技巧
来源:互联网 发布:局域网控制软件破解版 编辑:程序博客网 时间:2024/06/05 13:16
1.如何验证某个元素是否为空:
if ($('#keks').html()) {//什么都没有找到;}
2.如何禁用右键单击上下文菜单:
$(document).bind('contextmenu',function(e){ return false;});
3. 如何使用closest来取得父元素:
$('#searchBox').closest('div');
4. 如何强制在弹出窗口中打开链接:
jQuery('a.popup').live('click', function(){ newwindow=window.open($(this).attr('href'),'','height=200,width=150'); if (window.focus) { newwindow.focus(); } return false;});5. 如何强制在新的选项卡中打开链接:
jQuery('a.newTab').live('click', function(){ newwindow=window.open($(this).href); jQuery(this).target = "_blank"; return false;});
6.预加载图片
(function($) { var cache = []; // Arguments are image paths relative to the current page. $.preLoadImages = function() { var args_len = arguments.length; for (var i = args_len; i--;) { var cacheImage = document.createElement('img'); cacheImage.src = arguments[i]; cache.push(cacheImage); } }jQuery.preLoadImages("image1.gif", "/path/to/image2.png");
7.预防对表单进行多次提交
$(document).ready(function() { $('form').submit(function() { if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') { jQuery.data(this, "disabledOnSubmit", { submited: true }); $('input[type=submit], input[type=button]', this).each(function() { $(this).attr("disabled", "disabled"); }); return true; } else { return false; } });});
8. 在窗口滚动时自动加载内容
var loading = false;$(window).scroll(function(){ if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){ if(loading == false){ loading = true; $('#loadingbar').css("display","block"); $.get("load.php?start="+$('#loaded_max').val(), function(loaded){ $('body').append(loaded); $('#loaded_max').val(parseInt($('#loaded_max').val())+50); $('#loadingbar').css("display","none"); loading = false; }); } }});$(document).ready(function() { $('#loaded_max').val(50);});
- jQuery技巧
- jQuery 技巧
- jQuery技巧
- jQuery技巧
- jQuery技巧
- jQuery技巧
- jQuery技巧
- jQuery技巧
- jQuery技巧
- jQuery 技巧
- jQuery技巧
- jquery技巧
- Jquery技巧
- jQuery 技巧
- jQuery技巧
- JQUERY技巧
- jquery技巧
- jquery技巧
- windows下安装Git客户端
- 程序员十个糟糕的行为
- MinGW---window平台下的Gcc开发环境
- <内核情景分析> 2.8:页面的定期换出 总结
- C语言结构、联合、位操作、位域和枚举
- jquery技巧
- STL版本的循环链表
- Oracle回收站管理
- MFC 多文档程序 手动创建新文档的方法
- D-Link DWA-160 wifi抓包
- Can't create thread to send RTP packets (SIPP 并发错误)
- ORACLE PL/SQL编程--异常错误处理
- ARM与X86不具备可比性 性能差距可大上千倍
- Ajax jsp指定提交