分享jQuery封装好的一些常用操作
1. 禁止右键点击
$(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 //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$(document).ready(function() {// Target Firefox 2 and aboveif ($.browser.mozilla && $.browser.version >= "1.8" ){ // do something}// Target Safariif( $.browser.safari ){ // do something}// Target Chromeif( $.browser.chrome){ // do something}// Target Caminoif( $.browser.camino){ // do something}// Target Operaif( $.browser.opera){ // do something}// Target IE6 and belowif ($.browser.msie && $.browser.version <= 6 ){ // do something}// Target anything above IE6if ($.browser.msie && $.browser.version > 6){ // do something}});$(document).ready(function() {jQuery.preloadImages = function(){ for(var i = 0; i<ARGUMENTS.LENGTH; jQuery(?<img { i++)>").attr("src", arguments[i]); }}// how to use$.preloadImages("image1.jpg");});$(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>});$(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>});有时候你需要确保图片完成加载完成以便执行后面的操作:$('img').load(function () { console.log('image load successful');});如果你碰巧在你的网站上发现了破碎的图像链接,你可以用一个不易被替换的图像来代替它们。添加这个简单的代码可以节省很多麻烦:
$('img').on('error', function () { $(this).prop('src', 'img/broken.png');});$(document).ready(function() { window.setTimeout(function() { // do something }, 1000);});分享jQuery封装好的一些常用操作的更多相关文章
- jQuery对select标签的常用操作
1.获取当前选中项的value. $("#selector").val(); 2.获取当前选中项的text. $("#selector").find(" ...
- mysql的常用操作的封装
1.概述: 为了把繁琐的操作简化成简单的类,设计了2个类用来封装了mysql的常用操作,以便使用者可以方便地使用. 2.组成 1)数据库操作类CDatabaseConnect 2)SQL对象类CSql ...
- js,jQuery数组常用操作小结
一.js中数组常用操作小结 (1) shift:删除原数组第一项,并返回删除元素的值:如果数组为空则返回undefined var a = [1,2,3,4,5]; var b = a.shift() ...
- Ajax-04 jQuery Ajax 常用操作
jQuery jQuery 其实就是一个JavaScript的类库,其将复杂的功能做了上层封装,使得开发者可以在其基础上写更少的代码实现更多的功能. jQuery Ajax a.概述 jQuery 不 ...
- 自己使用Jquery封装各种功能分享
自己使用Jquery封装各种功能分享: 左右滚动图片 瀑布流 流动显示列表 广告切换 头像切换And广告切换 获取搜索引擎的来源关键字 上面列表中展示的功能都是使用jquery进行封装实现的,希望大家 ...
- .Net Excel操作之NPOI(二)常用操作封装
一.Excel数据导出常用操作 1.指定表头和描述 2.指定数据库中读出的数据集合 二.ExcelExport封装 /// <summary> /// Excel常用的表格导出逻辑封装 / ...
- jQuery常用操作
jQuery jQuery是一个轻量级的JS库,是一个被封装好的JS文件,提供了更为简便的元素操作方式,jQuery封装了DOM. 使用jQuery 引入jQuery文件 <scrtipt sr ...
- JQuery常用操作实现方式
http://www.cnblogs.com/guomingfeng/articles/2038707.html 一个优秀的 JavaScript 框架,一篇 jQuery 常用方法及函数的文章留存备 ...
- nodejs 进阶:封装所有对数据库的常用操作
//这个模块里面封装了所有对数据库的常用操作 var MongoClient = require('mongodb').MongoClient; var settings = require(&quo ...
随机推荐
- linux安装rzsz(lrzsz)
lrzsz是一个unix通信套件提供的,X,Y和ZModem文件传输协议,可以用在Windows与linux系统之间的文件传输,体积小速度快,可以与xshell工具配合使用. (1)在线安装 yum ...
- C# JAVAMemory model
http://www.cl.cam.ac.uk/~pes20/weakmemory/index.html http://preshing.com/20120913/acquire-and-releas ...
- 解决MAC下ctags -R无效的问题
MAC下自带了ctags,与我们常用的是不同的. 我们需要去重新下载一个ctags并重新安装 1.去http://ctags.sourceforge.net/下载Ctags的最新版本源代码 2.tar ...
- 新浪微博5s钟后跳转页面
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- python2安装pymongo
wget --no-check-certificate https://pypi.python.org/packages/source/p/pymongo/pymongo-2.6.3.tar.gz#m ...
- registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
问题是tomcat的版本问题,tomcat新检测机制导致的这个问题,换版本可以解决问题,但不建议这么做,租用服务器不是你说换就换的.其实问题根源是BasicDataSource,BasicDataSo ...
- eclipse javaee 插件安装
eclipese 精简版安装java ee插件 , 按图走 (eclipse 版本 : Indigo Service Release 1 (3.7.1)) java ee 在线安装地址: htt ...
- php结合msf反弹内网shell
感谢: perl6大佬分享的姿势. MSF: msf > use payload/php/bind_phpmsf exploit(handler) > set PAYLOAD payloa ...
- tomcat7和jetty启动的pom.xml配置
<plugins> <!-- tomcat7 --> <plugin> <groupId>org.apache.tomcat.maven</gro ...
- 【WPF】用代码给集合(Collection)容器动态添加子元素(Item)
需求:如何向 TabControl 中添加选项卡项. 问题:做的TabControl分页栏想要通过代码来控制添加的子元素.同理可以将解决思路拓展到用于其他的集合控件添加子元素的问题. 在布局文件She ...