zoukankan      html  css  js  c++  java
  • jquery函数$.proxy简单示例

    来自于《jquery 权威指南》

    ------------------------------

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery</title>
    <style type="text/css">
    body,div,ul,li,p{margin: 0;padding: 0; font-size: 13px;}
    ul{list-style-type: none;}
    a{text-decoration: none;}
    div{margin: 5px;padding: 10px;border: solid 1px #666;background-color: #eee;width: 260px;}
    input{margin: 5px;}
    .btn{border: solid 1px #666;padding: 2px; width: 50px;}
    
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jqueryui/ui/jquery-ui.js"></script>
    <script type="text/javascript">
        $(function(){
            var objMyInfo = {
                name: "王美丽",
                sex: "",
                ShowEvent: function(){
                    $(".divShow").html("姓名:" + this.name + "<br />性别:" + this.sex);
                }
            };
            $("#btn1").bind("click",$.proxy(objMyInfo.ShowEvent,objMyInfo));
        });
    
    </script>
    </head>
    <body>
    <input id="btn1" type="button" value="显示" class="btn" />
    <div class="divShow"></div>
    </body>
    </html>

    执行效果:

    -----------------------------------------------------------------

    #btn1的click事件,要调用其它作用域的事件函数,需要用到$.proxy工具函数。

  • 相关阅读:
    如何学习Java基础
    什么阻碍手动测试发挥价值
    API自动化测试指南
    筛选自动化测试用例的技巧
    拷贝HttpRequestBase对象
    测试自动化的边缘DevTestOps
    2019年浏览器市场份额排行榜
    CentOS7 通过 YUM 升级 VIM8
    vim配置go语法高亮
    打开程序总是会提示 "Enter password to unlock your login keyring"
  • 原文地址:https://www.cnblogs.com/phpway/p/3488238.html
Copyright © 2011-2022 走看看