将自身价值传递给功能

Ani*_*cho 0 javascript jquery

我有以下内容你可以看到我试图this通过这个函数来实现这是可能的JavaScript\jQuery如果是这样如何?似乎无法找到任何我认为我的术语错误的东西.

function pageLoad(sender, args) {
    if (args.get_isPartialLoad()) {
        jQuery(".ShowPleaseWait").click(function () {
            processingReplacer("Please Wait...", this);
        });
        jQuery(".ShowProcessing").click(function () {
            processingReplacer("Processing...", this);
        });
    }
}

function processingReplacer(message, this) { 
        if (Page_IsValid) {
            jQuery(this).hide();
            jQuery(this).after("<img id='" + jQuery(this).attr('id') + "' class='" + jQuery(this).attr('class') + "' src='/content/images/processing.gif' /> " + message);
            alert("woohoo"); 
        }
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*Jon 5

您不能将其this用作函数参数的名称.将其更改为其他内容:

function processingReplacer(message, target) { 
    if (Page_IsValid) {
        jQuery(target).hide();
        jQuery(target).after("<img id='" + jQuery(target).attr('id') + "' class='" +
           jQuery(target).attr('class') + "' src='/content/images/processing.gif' /> " +
           message);
        alert("woohoo"); 
    }
}
Run Code Online (Sandbox Code Playgroud)