的default.html和外面我有default.html中內的下列頁面元素:的Win8:訪問頁面元素default.js
<div id ="content">
<div id="output"></div>
</div>
並在default.js:
...
args.setPromise(WinJS.UI.processAll().done(function()
{
var theOutput = document.getElementById("output");
theOutput.innerText = "This is the output";
}));
....
這成功地產生了只有文本「這是輸出」的應用程序
但是如果我移動到這個新的腳本的script.js:
(function()
{
"use strict";
var theOutput = document.getElementById("output");
theOutput.innerText = "This is the output";
}());
而且添加的script.js在default.html中的腳本參考:
<script src="/js/script.js"></script><script src="/js/script.js"></script>
我得到的錯誤
JavaScript runtime error: Unable to set property 'innerText' of undefined or null reference
如何在default.js之外的其他腳本中訪問輸出div?
您可以使用相同的樣板'WinJS.UI.processAll( )'代碼,它也應該工作。 – kamranicus