请选择 进入手机版 | 继续访问电脑版

弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 1295|回复: 0

【js】创建带对象的函中函数

[复制链接]
发表于 2020-10-25 10:10:32 | 显示全部楼层 |阅读模式
创建带bar1,bar2函数的foo函数
var foo = {
    bar1: function me() {
        var index = 1;
        alert(me);
    },
    bar2: function me() {
        var index = 2;
        alert(me);
    }
};

foo.bar1(); // Shows the first one
foo.bar2(); // Shows the second one

创建类似于$.post()的jquery函数
$.extend({
    send: function (url, args, tar) {
        console.log("222");
        var body = $(document.body),
            form = $("<form method='post' target='" + tar + "'></form>"),
            input;
        form.attr({ "action": url });
        $.each(args, function (key, value) {
            input = $("<input type='hidden'>");
            input.attr({ "name": key });
            input.val(value);
            form.append(input);
        });

        form.appendTo(document.body);
        form.submit();
        document.body.removeChild(form[0]);
    }
});

$.send(url, args, tar);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-3-28 22:55 , Processed in 0.056630 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表