1) 禁用鼠标右键单击

  jQuery程序员可以使用此代码在网页上禁用鼠标右键点击。

1
2
3
4
5
6
7
8
9
10
$(document).ready(function() {
    //catch the right-click context menu
    $(document).bind("contextmenu",function(e) {                
        //warning prompt - optional
        alert("No right-clicking!");
 
        //delete the default context menu
        return false;
    });
});

  2) 利用jQuery调整文字大小

  使用此代码,用户可以重新网站上文字的大小(增大和减少)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$(document).ready(function() {
    //find the current font size
    var originalFontSize = $('html').css('font-size');
 
    //Increase the text size
    $(".increaseFont").click(function() {
        var currentFontSize = $('html').css('font-size');
        var currentFontSizeNumber = parseFloat(currentFontSize, 10);
 
        var newFontSize = currentFontSizeNumber*1.2;
        $('html').css('font-size', newFontSize);
        return false;
    });
 
    //Decrease the Text Size
    $(".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;
    });
 
    // Reset Font Size
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  });
});

  3) 在新的Windows打开链接

  Try this code and increase your site impressions because using this jquery code users will go on new window after clicking on any link of your site. Code is below: -

1
2
3
4
5
$(document).ready(function() {
    //select all anchor tags that have http in the href
    //and apply the target=_blank
    $("a[href^='http']").attr('target','_blank');
});

  4) Style Sheets Swap

  Swap style sheets using this code and the “Style sheets swap” script  is below: -

1
2
3
4
5
6
$(document).ready(function() {
    $("a.cssSwap").click(function() {
        //swap the link rel attribute with the value in the rel   
        $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));
    });
});

  5) 回到顶部链接

  That is very common function you can see on eve site nowadays is ” Back to Top”. This functionality is very useful for long pages for make short in a single click. Visit this code below: -

1
2
3
4
5
6
7
$(document).ready(function() {
    //when the id="top" link is clicked
    $('#top').click(function() {
        //scoll the page back to the top
        $(document).scrollTo(0,500);
    }
});

  6) 获取鼠标光标的x和y轴

  You can find the values of X and Y coordinator of mouse pointer. Code is blow : -

1
2
3
4
$().mousemove(function(e){
    //display the x and y axis values inside the P element
    $('p').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
});

  7) 检测当前鼠标坐标

  使用这个脚本,你可以在jQuery所支持的任何Web浏览器找到当前鼠标的坐标。代码如下:

1
2
3
4
5
$(document).ready(function() {
$().mousemove(function(e)
{
$('# MouseCoordinates ').html("X Axis Position = " + e.pageX + " and Y Axis Position = " + e.pageY);
});

});

  8) 在jQuery中预加载图片

  此图像预加载的脚本有助于非常快速加载图像或网页。你不必等待图像加载。代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
jQuery.preloadImagesInWebPage = function()
{
     for(var ctr = 0; ctr<arguments.length; ctr++)
{
jQuery("<img alt="">").attr("src", arguments[ctr]);
}
}
To use the above method, you can use the following piece of code:
$.preloadImages("image1.gif", "image2.gif", "image3.gif");
To check whether an image has been loaded, you can use the following piece of code:
$('#imageObject').attr('src', 'image1.gif').load(function() {
alert('The image has been loaded…');
});

8个对程序员来说有用的jQuery小贴士和技巧的更多相关文章

  1. 30个有关Python的小技巧,给程序员的 30 个基本 Python 贴士与技巧

    30个有关Python的小技巧 2013/07/04 · Python, 开发 · 4 评论 · Python 分享到: 66 本文由 伯乐在线 - Kevin Sun 翻译.未经许可,禁止转载!英文 ...

  2. 一:对程序员来说CPU是什么?

    0.开篇    (1)程序是什么?          指示计算机每一步动作的一组指令     (2)程序是由什么组成的?          指令和数据     (3)什么是机器语言?         ...

  3. 【python】对于程序员来说,2018刑侦科推理试卷是问题么?

    最近网上很火的2018刑侦科推理试卷,题目确实很考验人逻辑思维能力. 可是对于程序员来说,这根本不是问题.写个程序用穷举法计算一遍即可,太简单. import itertools class Solu ...

  4. 18个Java8日期处理的实践,对于程序员太有用了!

    18个Java8日期处理的实践,对于程序员太有用了! Java 8 推出了全新的日期时间API,在教程中我们将通过一些简单的实例来学习如何使用新API. Java处理日期.日历和时间的方式一直为社区所 ...

  5. (转)程序员应该知道的10个eclipse调试技巧

    调试不仅可以查找到应用程序缺陷所在,还可以解决缺陷.对于Java程序员来说,他们不仅要学会如何在Eclipse里面开发像样的程序,更需要学会如何调试程序.本文介绍了Java程序员必知的10个调试技巧, ...

  6. Java程序员应该知道的10个Eclipse调试技巧

    Eclipse是众多Java程序员实用的开发工具,其中开发技巧也是繁多,但作为优秀的Java程序员,需要掌握最起码的调试技巧. 1 条件断点 2 异常断点 3 监视点 4 评估/检查 5 修改变量值 ...

  7. 从程序员的角度分析微信小程序(编程语言:用到什么学什么)

    从程序员的角度分析微信小程序(编程语言:用到什么学什么) 一.总结 一句话总结:微信小程序原理就是用JS调用底层native组件,和React Native非常类似.(需要时,用到时再学) 1.选择语 ...

  8. (第一章)对程序员来说CPU是什么

    这几天,看到一本书,<程序是怎么跑起来的>,觉得之前都没有完整的看完一本书,现在要从这本书开始,慢慢的培养自己写读书笔记的习惯,不能度过去就忘了. 学习是一个螺旋上升的过程,不要指望一下子 ...

  9. 《程序是怎样跑起来的》读书笔记——第一章 对程序员来说CPU是什么

    1 程序的运行流程 2 CPU的组成 3 寄存器的主要种类和功能 "程序计数器"--决定程序流程的 4 条件分支和循环机制 4.1 顺序执行 4.2 选择分支 5 函数的调用机制 ...

随机推荐

  1. SQL语句之 知识补充

    SQL语句之 知识补充 一.存储过程 运用SQL语句,写出一个像函数的模块,这就是存储过程. 需求: 编写存储过程,查询所有员工 -- 创建存储过程(必须要指定结束符号) -- 定义结束符号 DELI ...

  2. SQLSERVER——查看阻塞信息(sp_who_lock优化无误版)

    经常会需要分析SQLSERVER的阻塞情况,尤其是某些SQL操作异常缓慢从而怀疑是有人在搞事情的情况下.网上有许多一模一样的帖子,是关于sp_who_lock这个存储过程的,然而,网上流传的这个是略有 ...

  3. VMWare虚拟机下CentOS 配置网络实现远程连接,提供Web访问

        最近使用VMWARE虚拟机当中redhat操作系统,感觉直接使用很不方便,于是就决定配置下redhat网络,通过本机远程工具SecureCRT来连接redhat使用.     环境说明:本机操 ...

  4. BZOJ 3876: [Ahoi2014]支线剧情 带下界的费用流

    3876: [Ahoi2014]支线剧情 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3876 Description [故事背景] 宅 ...

  5. BZOJ 4448: [Scoi2015]情报传递 树链剖分 主席树

    4448: [Scoi2015]情报传递 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4448 Description 奈特公司是一个巨 ...

  6. Caffe2(3)----下载现成的模型并使用

    Caffe2训练好的模型可在Model Zoo下载,下载的命令很简单,接下来以下载和使用squeezenet为例,进行简单说明. 1.浏览可下载的模型 已有模型都放在github上,地址:https: ...

  7. php在linux后台执行

    <?php ignore_user_abort();//后台运行 ini_set('default_socket_timeout', -1);//socket不超时 set_time_limit ...

  8. redis的搜索组件 redis-search4j

    redis-search4j是一款基于redis的搜索组件. 特点 1.基于redis,性能高效 2.实时更新索引 3.支持Suggest前缀.拼音查找(AutoComplete功能) 4.支持单个或 ...

  9. A* search算法解迷宫

    这是一个使用A* search算法解迷宫的问题,细节请看:http://www.laurentluce.com/posts/solving-mazes-using-python-simple-recu ...

  10. 3.3V与5V电平双向转换

    http://www.amobbs.com/thread-5541344-1-2.html 3.3V转5V:S3输入为0V时,NMOS管导通,S5=S3=0V:S3输入为3.3V时,NMOS管截止,S ...