源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Jquery常用技巧收集整理篇

  • 时间:2021-10-25 03:42 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Jquery常用技巧收集整理篇
比如有禁止右键点击、隐藏搜索文本框文字、在新窗口中打开链接、检测浏览器、预加载图片等等。具体如下: 禁止右键点击
[url=http://www.opensourcehunter.com]
检测浏览器 注: 在版本jQuery 1.4中,$.support 替换掉了$.browser 变量。 预加载图片
[url=default.css]// the links <A class=Styleswitcher href="#" rel=default.css>Default Theme</A> <A class=Styleswitcher href="#" rel=red.css>Red Theme</A> <A class=Styleswitcher href="#" rel=blue.css>Blue Theme</A> });
列高度相同 如果使用了两个CSS列,使用此种方式可以是两列的高度相同。
动态控制页面字体大小
[url=#top]});
获得鼠标指针XY值
验证元素是否为空
[url=index.html]});
ID与Class之间转换当改变Window大小时,在ID与Class之间切换
克隆对象
[u]复制代码[/u] 代码如下:
$(document).ready(function() { var cloned = $('#id').clone(); // how to use <DIV idid=id></DIV> });
使元素居屏幕中间位置
[u]复制代码[/u] 代码如下:
$(document).ready(function() { jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); return this; } $("#id").center(); });
写自己的选择器
[u]复制代码[/u] 代码如下:
$(document).ready(function() { $.extend($.expr[':'], { moreThen1000px: function(a) { return $(a).width() > 1000; } }); $('.box:moreThen1000px').click(function() { // creating a simple js alert box alert('The element that you have clicked is over 1000 pixels wide'); }); });
统计元素个数
[u]复制代码[/u] 代码如下:
$(document).ready(function() { $("p").size(); });
使用自己的Bullets
[u]复制代码[/u] 代码如下:
$(document).ready(function() { $("ul").addClass("Replaced"); $("ul > li").prepend("‒ "); // how to use ul.Replaced { list-style : none; } });
引用Google主机上的jQuery类库
[u]复制代码[/u] 代码如下:
//Example 1 <SCRIPT src="http://www.google.com/jsapi"></SCRIPT> <SCRIPT type=text/javascript> google.load("jquery", "1.2.6"); google.setOnLoadCallback(function() { // do something }); </SCRIPT><SCRIPT src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type=text/javascript></SCRIPT> // Example 2:(the best and fastest way) <SCRIPT src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type=text/javascript></SCRIPT>
禁用jQuery(动画)效果
[u]复制代码[/u] 代码如下:
$(document).ready(function() { jQuery.fx.off = true; });
与其他JavaScript类库冲突解决方案
[u]复制代码[/u] 代码如下:
$(document).ready(function() { var $jq = jQuery.noConflict(); $jq('#id').show(); });
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部