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'/>

  • 相关阅读:
    写一个含数字,拼音,汉字的验证码生成类
    Vue.js 学习示例
    webapi
    webapi
    WebApi接口
    WebApi接口
    WebApi
    个人插件锦集
    ShenNiu.MVC管理系统
    Centos6搭建Samba服务并使用Windows挂载
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/2528346.html
Copyright © 2011-2022 走看看