我有以下内容,您可以看到我正在尝试对函数传递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");
}
}
最佳答案
你可以这样做:
processingReplacer.call(this, "Please Wait...");
...
function processingReplacer(message) {
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");
}
}
使用call,您可以设置
this
的上下文。但是,乔恩的答案可能更具可读性。