【发布时间】:2018-11-19 00:38:34
【问题描述】:
在这里受到指责后,我尝试从头开始重新编码。我需要为出现在 div 中的 HTML 文件加载 JS 文件...
<script type="text/javascript">
function getInclude(strIncludeContainer, strIncludeURL)
{
var strPage = '';
var intIndexOfBodyOpen = 0;
var intIndexOfBodyClose = 0;
var objXhttp;
objXhttp = new XMLHttpRequest();
objXhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
strPage = this.responseText;
intIndexOfBodyOpen = strPage.indexOf('<body>');
intIndexOfBodyClose = strPage.indexOf('</body>');
document.getElementById(strIncludeContainer).innerHTML = strPage.substring(intIndexOfBodyOpen + 6, intIndexOfBodyClose);
}
};
objXhttp.open("GET", strIncludeURL, true);
objXhttp.send();
}
getInclude("divUnifiedAppWording", "../mpage/Unified_App_Wording");
var script = document.createElement("script");
script.src = "../resource/resmgr/scripts/unified_app.js";
$container.appendChild(script);
</script>
<div id="divUnifiedAppWording"></div>
function getInclude 工作正常,但我无法加载unified_app.js 中的Javascript。作为参考,在unified_app.js 我有以下脚本:
const date = new Date();
let offset = 0;
const threshold = new Date();
threshold.setMonth(3); //January is 0!
threshold.setDate(3);
if (Date.now() > threshold) {
offset = 1;
}
var theDate = new Date();
var award_year1 = date.getFullYear() + offset;
var award_year2 = date.getFullYear() + 1 + offset;
console.log(award_year1);
console.log(award_year2);
在花了几天时间试图找出解决我的问题的方法后,我真的迷失了!我觉得找到一个简单的解决方案来解决这个问题应该不难。希望我没有在这里吠叫错误的树...在此先感谢。
【问题讨论】:
标签: javascript