AJax技术

常用jquery使用技巧

字号+ 作者:H5之家 来源:H5之家 2016-01-17 12:47 我要评论( )

常用jquery使用技巧

一、ajax的应用
$.ajax({url: 'stat.php', type: 'POST', data:{Name:"keyun"}, dataType: 'html', timeout: 1000, error: function(){alert('Error loading PHP document');}, success: function(result){alert(result);} });
二、禁止鼠标右键

$(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() { $('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() { window.setTimeout(function() { // do something }, 1000); });

六、使元素居于屏幕中间
$(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(); });

七、引用google主机上的jquery类库
<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的日常使用中能够起到一定的作用。

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • JQuery实现Ajax加载图片的方法

    JQuery实现Ajax加载图片的方法

    2016-02-24 17:01

  • jQuery.ajax()的相关参数及使用

    jQuery.ajax()的相关参数及使用

    2016-02-08 16:00

  • 05 jQuery与Ajax以及序列化

    05 jQuery与Ajax以及序列化

    2016-02-08 12:08

  • jquery.ajax制作帝国cms6.6快速登录插件

    jquery.ajax制作帝国cms6.6快速登录插件

    2016-02-06 15:00

网友点评
i