iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >jQuery 1.4实用技巧有哪些
  • 477
分享到

jQuery 1.4实用技巧有哪些

2024-04-02 19:04:59 477人浏览 八月长安
摘要

这篇文章主要介绍了Jquery 1.4实用技巧有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。禁止右键点击$(document).rea

这篇文章主要介绍了Jquery 1.4实用技巧有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

禁止右键点击

$(document).ready(function(){     $(document).bind("contextmenu",function(e){        return false;       });     });

隐藏搜索文本框文字

$(document).ready(function() {     $("input.text1").val("Enter your search text here");        textFill($('input.text1'));     });     function textFill(input){ //input focus text function        var originalvalue = input.val();        input.focus( function(){      if( $.trim(input.val()) == originalvalue ){ input.val(''); }     });      input.blur( function(){         if( $.trim(input.val()) == '' ){ input.val(originalvalue); }     });     }

在新窗口中打开链接

$(document).ready(function() {     //Example 1: Every link will open in a new window     $('a[href^="Http://"]').attr("target", "_blank");     //Example 2: Links with the rel="external" attribute will only open in a new window     $('a[@rel$='external']').click(function(){          this.target = "_blank";     });      });     // how to use     <A href="http://www.opensourcehunter.com" rel=external>open link</A>

检测浏览器

注: 在版本jQuery 1.4中,$.support 替换掉了$.browser 变量。

$(document).ready(function() {     // Target Firefox 2 and above        if ($.browser.mozilla && $.browser.version >= "1.8" ){         // do something         }     // Target Safari     if( $.browser.safari ){     // do something     }     // Target Chrome     if( $.browser.chrome){     // do something      }     // Target Camino     if( $.browser.camino){     // do something      }     // Target Opera     if( $.browser.opera){     // do something      }     // Target IE6 and below     if ($.browser.msie && $.browser.version <= 6 ){     // do something      }     // Target anything above IE6     if ($.browser.msie && $.browser.version > 6){     // do something     }     });

预加载图片

$(document).ready(function() {        jQuery.preloadImages = function()       {          for(var i = 0; i").attr("src", arguments[i]);       }    };    // how to use    $.preloadImages("image1.jpg");     });

页面样式切换

$(document).ready(function() {      $("a.Styleswitcher").click(function() {      //swicth the LINK REL attribute with the value in A REL attribute     $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));        });      // how to use     // place this in your header      <LINK href="default.CSS" type=text/css rel=stylesheet>     // 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列,使用此种方式可以是两列的高度相同。

$(document).ready(function() {       function equalHeight(group) {       tallest = 0;       group.each(function() {        thisHeight = $(this).height();        if(thisHeight > tallest) {           tallest = thisHeight;        }      });      group.height(tallest);     }      // how to use      $(document).ready(function() {         equalHeight($(".left"));         equalHeight($(".right"));        });      });

动态控制页面字体大小

$(document).ready(function() {        // Reset the font size(back to default)       var originalFontSize = $('html').css('font-size');        $(".resetFont").click(function(){       $('html').css('font-size', originalFontSize);      });        // Increase the font size(bigger font0       $(".increaseFont").click(function(){      var currentFontSize = $('html').css('font-size');     var currentFontSizeNum = parseFloat(currentFontSize, 10);     var newFontSize = currentFontSizeNum*1.2;      $('html').css('font-size', newFontSize);         return false;      });      // Decrease the font size(smaller font)     $(".decreaseFont").click(function(){      var currentFontSize = $('html').css('font-size');     var currentFontSizeNum = parseFloat(currentFontSize, 10);     var newFontSize = currentFontSizeNum*0.8;      $('html').css('font-size', newFontSize);       return false;       });     });

返回页面顶部功能

$(document).ready(function() {     $('a[href*=#]').click(function() {        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')        && location.hostname == this.hostname) {        var $target = $(this.hash);     $target = $target.length && $target       || $('[name=' + this.hash.slice(1) +']');       if ($target.length) {      var targetOffset = $target.offset().top;      $('html,body')       .animate({scrollTop: targetOffset}, 900);       return false;     }      }     });      // how to use     // place this where you want to scroll to      <A name=top></A>       // the link     <A href="#top">Go to top</A>     });

获得鼠标指针XY值

   $(document).ready(function() {        $().mousemove(function(e){          //display the x and y axis values inside the div with the id XY        $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);      });      // how to use      <DIV id=XY></DIV>     });

验证元素是否为空

  $(document).ready(function() {         if ($('#id').html()) {         // do something       }     });

替换元素

$(document).ready(function() {     $('#id').replaceWith('      <DIV>I have been replaced</DIV>      );     });

jQuery延时加载功能

$(document).ready(function() {          window.setTimeout(function() {          // do something           }, 1000);      });

移除单词功能

$(document).ready(function() {         var el = $('#id');         el.html(el.html().replace(/Word/ig, ""));      });

验证元素是否存在于jQuery对象集合中

$(document).ready(function() {         if ($('#id').length) {         // do something      }     });

使整个DIV可点击

$(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      <DIV><A href="index.html">home</A></DIV>     });     ID与Class之间转换当改变Window大小时,在ID与Class之间切换   $(document).ready(function() {         function checkwindowsize() {        if ( $(window).width() > 1200 ) {           $('body').addClass('large');         }        else {            $('body').removeClass('large');              }      }     $(window).resize(checkWindowSize);     });

克隆对象

$(document).ready(function() {        var cloned = $('#id').clone();        // how to use      <DIV idid=id></DIV>     });

使元素居屏幕中间位置

$(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();      });

写自己的选择器

$(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');        });      });

统计元素个数

$(document).ready(function() {     $("p").size();     });

使用自己的Bullets

$(document).ready(function() {       $("ul").addClass("Replaced");       $("ul > li").prepend("‒ ");       // how to use       ul.Replaced { list-style : none; }      });

引用Google主机上的jQuery类库

//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(动画)效果

$(document).ready(function() {         jQuery.fx.off = true;      });

与其他JavaScript类库冲突解决方案

$(document).ready(function() {        var $jq = jQuery.noConflict();        $jq('#id').show();      });

感谢你能够认真阅读完这篇文章,希望小编分享的“jQuery 1.4实用技巧有哪些”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网JavaScript频道,更多相关知识等着你来学习!

--结束END--

本文标题: jQuery 1.4实用技巧有哪些

本文链接: https://www.lsjlt.com/news/84694.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • jQuery 1.4实用技巧有哪些
    这篇文章主要介绍了jQuery 1.4实用技巧有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。禁止右键点击$(document).rea...
    99+
    2024-04-02
  • jQuery适用技巧有哪些
    今天小编给大家分享一下jQuery适用技巧有哪些的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下...
    99+
    2024-04-02
  • jQuery、zepto、js常用小技巧有哪些
    小编给大家分享一下jQuery、zepto、js常用小技巧有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!jQuery/ze...
    99+
    2024-04-02
  • Git有哪些实用技巧
    本篇内容主要讲解“Git有哪些实用技巧”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Git有哪些实用技巧”吧!将几个commit压缩成一个⚠️ 这里有一点要特别...
    99+
    2024-04-02
  • vue有哪些实用技巧
    本篇内容主要讲解“vue有哪些实用技巧”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“vue有哪些实用技巧”吧!监听组件的生命周期比如有父组件 Parent 和子...
    99+
    2024-04-02
  • PyCharm实用技巧有哪些
    这期内容当中小编将会给大家带来有关PyCharm实用技巧有哪些,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。今天主要跟大家介绍PyCharm的高效使用技巧!以下代码演示是在 Mac 环境下,Windows...
    99+
    2023-06-16
  • Python实用技巧有哪些
    这篇文章主要讲解了“Python实用技巧有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python实用技巧有哪些”吧!整理字符串输入整理用户输入的问题在编程过程中极为常见。通常情况下,...
    99+
    2023-06-16
  • javascript实用技巧有哪些
    本篇内容介绍了“javascript实用技巧有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、js整数的操作使用|0和~~可以将浮点转...
    99+
    2023-06-25
  • jQuery中EasyUI开发技巧有哪些
    这篇文章主要为大家展示了“jQuery中EasyUI开发技巧有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“jQuery中EasyUI开发技巧有哪些”这篇文...
    99+
    2024-04-02
  • jQuery操作radio的技巧有哪些
    以下是一些使用jQuery操作radio的技巧:1. 设置选中的radio按钮:使用`prop()`方法将radio按钮的`chec...
    99+
    2023-08-15
    jQuery radio
  • NPM实用技巧有哪些
    今天小编给大家分享一下NPM实用技巧有哪些的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。1...
    99+
    2024-04-02
  • PowerBuilder实用技巧有哪些
    以下是一些PowerBuilder实用技巧: 使用DataWindow对象的自动过滤功能来简化数据过滤和排序操作。可以通过设置F...
    99+
    2023-10-24
    PowerBuilder
  • css实用技巧有哪些
    这篇文章主要讲解了“css实用技巧有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“css实用技巧有哪些”吧!1、如何清除图片下方出现几像素的空白间隙?方...
    99+
    2024-04-02
  • 有哪些Python实用技巧
    本篇内容主要讲解“有哪些Python实用技巧”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“有哪些Python实用技巧”吧!1. 使用youtube-dl下载YouTube视频你可以使用Pytho...
    99+
    2023-06-16
  • jquery中ajax请求小技巧有哪些
    这篇文章主要为大家展示了“jquery中ajax请求小技巧有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“jquery中ajax请求小技巧有哪些”这篇文章吧...
    99+
    2024-04-02
  • VB.NET List实用技巧有哪些
    这篇文章给大家分享的是有关VB.NET List实用技巧有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。要使用VB.NET List,我们需要了解如何部署.NET框架所提供的多种方法。这也将是本文要介绍的内容...
    99+
    2023-06-17
  • Python实用的技巧有哪些
    这篇文章主要讲解了“Python实用的技巧有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python实用的技巧有哪些”吧!1. 列表推导式有人或许以前听说过这些。Python中的一种编...
    99+
    2023-06-16
  • Android TextView实用技巧有哪些
    今天小编给大家分享一下Android TextView实用技巧有哪些的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。...
    99+
    2023-07-05
  • 实用的JavaScript技巧有哪些
    本篇内容主要讲解“实用的JavaScript技巧有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“实用的JavaScript技巧有哪些”吧!1 &nd...
    99+
    2024-04-02
  • jQuery中的常用到的技巧有哪些呢
    jQuery中的常用到的技巧有哪些呢,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。1.当document文档就绪时执行JavaScript代码。我们为什么使用j...
    99+
    2023-06-17
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作