Javascript函数未运行且无错误
下面是我的函数,它被放在自己的文件(Javascript/submitDate.js)中: 在我用索引加入页面之前,它运行得很好。(当我将所有javascript和页面布局放在一个文件中时) 以下是代码的页面(projectMain.html):Javascript函数未运行且无错误,javascript,html,function,onload,Javascript,Html,Function,Onload,下面是我的函数,它被放在自己的文件(Javascript/submitDate.js)中: 在我用索引加入页面之前,它运行得很好。(当我将所有javascript和页面布局放在一个文件中时) 以下是代码的页面(projectMain.html): <html> <div id="container"> <header> <h3>Entries close on the 10th of March</h3> &
<html>
<div id="container">
<header>
<h3>Entries close on the 10th of March</h3>
</header>
<section>
<aside onload="submitDate();">
Last submitted:
</br>
<input type="date" id="dateShow" readonly>
</aside>
</section>
参赛作品将于3月10日截止
编辑3.0:
这是我的索引:
<html>
<head>
<title>Sample Template</title>
<link rel="stylesheet" language="text/css" href="CSS/stylesheet.css"/>
<script language="javascript" src="Javascript/AJAX.js"></script>
</head>
<body onload="javascript:changePage('home');">
<h1>Little Big Planet</h1>
<div class="menu">
<a onclick="javascript:changePage('home');">Home</a>
<a onclick="javascript:changePage('powerups');">Power Ups</a>
<a onclick="javascript:changePage('bots');">Sackbots</a>
<a onclick="javascript:changePage('costumes');">Costumes</a>
<a onclick="javascript:changePage('projectMain');">Form</a>
</div>
<br />
<div id="content">
</div>
<script type="text/javascript" src="Javascript/submitDate.js"></script>
</body>
</html>
样本模板
小行星
家
通电
麻袋机器人
服装
形式
您的HTML中有一个JavaScript格式的capitol“j”
搁置的元素没有onload
属性(或load
事件)。仅加载外部内容的元素(例如,。如果使用区分大小写的文件系统(URL为404),则无法调用该函数。在加载文档时尝试加载js
JS文件:
<aside>
Last submitted:
</br>
<input type="date" id="dateShow" readonly>
</aside>
<script>
submitDate();
</script>
在你的html中,你可以把它放在一边
document.onload = function(){
function submitDate(){
var time = new Date();
var nowDate =time.toISOString().slice(0,-14);
document.getElementById("dateShow").value=nowDate;
}
submitDate();
}();
因为他的文件夹有一个大写的jb,但他说它在javascript/submitDate.js
中。小写的“J”。你是对的,没有在顶部看到。很好地发现尝试了这一点,仍然没有改变。我应该把:放在html中标记的前面。将pathtojsfile更改为js文件所在的路径。检查控制台窗口在你的浏览器中检查加载脚本时的错误。我一直在使用AJAX javascript文件。这会有什么不同吗?你能用你正在使用的脚本文件编辑帖子吗?尝试了这个以及其他人的提示。一定是其他类型的错误。
document.onload = function(){
function submitDate(){
var time = new Date();
var nowDate =time.toISOString().slice(0,-14);
document.getElementById("dateShow").value=nowDate;
}
submitDate();
}();
<aside>
Last submitted:
</br>
<input type="date" id="dateShow" readonly>
</aside>
<script type="text/javascript" src="pathtojsfile"></script>