以下代碼與Firefox和Internet Explorer 8中的Dojo 1.5一起使用。爲什麼Dojo 1.6使用dojo.require無法在IE8中正確加載JavaScript文件?
使用Dojo 1.6,它仍然可以在Firefox中工作,但在IE8中不起作用。
當wrappingFunctionInPlainJsFile()
被調用時,我得到一個Object doesn't support this property or method
錯誤。
HTML頁面:
<div dojoType="widget.MyCustomWidget"></div>
在小部件/ MyCustomWidget.js
dojo.provide("widget.MyCustomWidget");
dojo.require("js.plainJsFile");
dojo.declare("widget.MyCustomWidget", [dijit._Widget, dijit._Templated], {
...
// this gets called when the widget is clicked on in the UI
run: function() {
wrappingFunctionInPlainJsFile();
},
...
});
在JS/plainJsFile.js
dojo.provide("js.plainJsFile");
function someFunction() {
}
function wrappingFunctionInPlainJsFile(){
new someFunction();
}
什麼我做錯了會有什麼想法不勝感激。
注意:如果我直接在HTML頁面上導入plainJsFile.js
而不是使用dojo.require
那麼我沒有問題。
您的'somefunction'缺少大括號'{}'。我認爲它有一個翻譯錯誤,對吧? – hugomg
您確定您的plainJsFile.js在您嘗試使用時已被加載?你是異步加載模塊嗎?如果是這樣,你需要使用dojo.ready()。 –
@missingno是的,錯字。謝謝。固定。 –