![](/img/trans.png)
[英]How do I get a return value from a Handler function in JavaScript?
[英]How do I return value from this function
我正在嘗試編寫一個插件,並想返回一些值:
(function ($) {
$.SmartMessageBox = function (settings, callback) {
var SmartMSG = 'hello', Content;
//some code
return SmartMSG;
}
})(jQuery);
但是當我這樣打來電話時,打招呼永遠不會返回給呼叫者
console.log($.SmartMessageBox(null,null))
我想念什么?
這樣調用console.log($.SmartMessageBox(null,null))
由於它是用$
注冊的,因此您應該像上面那樣使用
您可能在執行中錯過了$
:$ .Smart MessageBox(null,null);
您的代碼在chrome控制台中執行:
(function ($) {
$.SmartMessageBox = function (settings, callback) {
var SmartMSG = 'hello', Content;
//some code
return SmartMSG;
}
})(jQuery);
undefined
$.SmartMessageBox(null, null)
"hello"
只是在小提琴中測試了它的工作原理:
(function ($) {
SmartMessageBox = function (settings, callback) {
var SmartMSG = 'hello', Content;
//some code
return SmartMSG;
}
})(jQuery);
console.log(SmartMessageBox(null,null));
> `
$.fn.SmartMessageBox = function(settings, callback) {
return "my settings";
};
Alert($.SmartMessageBox());`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.