zoukankan      html  css  js  c++  java
  • Jquery扩展方法

    网上搜索了信息在编写JQUERY扩展方法有两种,一种是使用jquery.fn.extend,一种是jquery.extend.

    jquery.fn表示jquery.prototype,,给jquery对象添加方法。刚好用到扩展方法,并且使用jquery.fn,这里就写下jquery.fn的用法,这些网上很多,蛮写蛮写

    比如当点击 button时弹出一个textbox的值加一个参数值

    jquery.fn.extend({

          alertMessage:function(message){

              var txtboxValue = $(this).val();//使用$(this)表示对哪个对象添加了扩展方法,这里是指$('#textbox' )

              alert(txtboxValue + message);

         }

    });

    $(function(){

        $("input[name='btn' ]").click(function(){

              $('#textbox' ).alertMessage("是字符串");

       })

    })

    html:

    <input type='button' name='btn' value='Alert'/>

    <input type='text' id='textbox' value='abc'/>

  • 相关阅读:
    bzoj3946
    bzoj3065
    bzoj1500
    bzoj1233
    bzoj1089
    bzoj1087
    bzoj1086
    if语句之猜拳
    if语句判断闰年、平年
    if语句判断身高体重是否标准
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/2528346.html
Copyright © 2011-2022 走看看