jQuery 一些方法技巧
2014-02-21 08:47
274 查看
//1. 去除页面的右键菜单 $(document).ready(function() { $(document).bind("contextmenu", function(e) { returnfalse; }); }); //2.当鼠标获得焦点、失去焦点的时候,input输入框文字处理: $(document).ready(function(){ $("input.text1").val("Enter your search text here"); textFill($('input.text1')); } ); function textFill(input){ var originalvalue = input.val(); input.focus(function(){ if( $.trim(input.val())== originalvalue ){ input.val(""); } } ); input.blur(function(){ if( $.trim(input.val())==""){ input.val(originalvalue); } } ); } //3、轻松切换css样式 $(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')); } ); } ); // place this in your header <link rel="stylesheet" href="default.css" type="text/css"> // the links <a href="#" rel="default.css">Default Theme</a> <a href="#" class="Styleswitcher" rel="red.css">Red Theme</a> <a href="#" class="Styleswitcher" rel="blue.css">Blue Theme</a> //4、高度相等的列 //如果您使用两个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")); } ); } ); //5、简单字体变大缩小 $(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); returnfalse; } ); // 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); returnfalse; } ); } ); //6、获取鼠标位置 $().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); } ); //7、判断一个元素是否为空 if($('#id').html()){ // do something } //8、替换元素 $('#id').replaceWith(' <div>I have been replaced</div> '); //9、判断元素是否存在 $(document).ready(function(){ if($('#id').length){ // do something } } ); //10、关闭jquery动画效果 $(document).ready(function(){ jQuery.fx.off=true; } ); //11、使用自己的jquery标识 $(document).ready(function(){ var $jq = jQuery.noConflict(); $jq('#id').show(); } ); //12、设置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(); } );原文地址
jquery http://www.jqueryba.com/170.html
相关文章推荐
- jquery的一些自己常用的方法技巧
- jquery 实现 Json 的一些转换方法
- jquery一些技巧总结
- Jquery 的一些方法
- jQuery常用的一些方法
- Yii2工作中的一些方法技巧
- 一些VC的快捷键以及调试方法技巧
- 关于这两天的学到的一些java编界面时的一些技巧或方法。
- jQuery操作表格(table)的常用方法、技巧汇总
- FIDDLER的使用方法及技巧总结(连载五)FIDDLER的一些故障排除
- 使用Visual Basic 6.0开发程序的一些方法技巧收集之一:注册表操作
- 11条jquery常用技巧和方法整理列表
- Jquery中的一些细节(一)--------------->Jquery加载调用多个函数(方法)需要注意的细节
- 11条jquery常用技巧和方法整理列表
- 一些VC的快捷键以及调试方法技巧
- jquery 中一些 特殊方法 的特殊使用 一览表
- Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解 JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写
- 个人总结的一些JavaScript技巧、实用函数、简洁方法、编程细节
- jQuery开发过程中的一些技巧
- jQuery编写widget的一些技巧分享