JQuery

jquery 获得鼠标指针 X/Y 值

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

  });

});

<div id="XY"></div>

jquery 得到html中元素的数量

 

$(document).ready(function() {

  $("p").size();

});

jquery 验证元素是否存在

 $(document).ready(function() {

  if ($('#id').length) {

    // do something

  }

});

jquery 元素居中间

 $(document).ready(function() {

  jQuery.fn.center = function() {

    this.css("position","absolute");

    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");

jquery page top

 $(document).ready(function() {

  $('a[href*=#]').click(function() {

   if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')

       && location.hostname == this.hostname) {

     var $target = $(this.hash);

jquery font resizing

 $(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

jquery 保持div的列高度相同

 $(document).ready(function() {

  function equalHeight(group) {

    tallest = 0;

    group.each(function() {

      thisHeight = $(this).height();

      if (thisHeight > tallest) {

        tallest = thisHeight;

jquery 预加载图片

 $(document).ready(function() {

  jQuery.preloadImages = function() {

    for(var i = 0; i < arguments.length; i++) {

      $("<img>").attr("src", arguments[i]);

    }

  }

 

  // how to use

jquery 隐藏搜索文本框文字

 $(document).ready(function() {

  $("input.text1").val("Enter your search text here");

  textFill($('input.text1'));

});

 

// input focus text function

function textFill(input) {

  var originalvalue = input.val();

  input.focus(function() {

jquery 禁止右键点击

 

$(document).ready(function(){

  $(document).bind("contextmenu", function(e) {

    return false;

  });

});

 

 

同步内容