Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从<;脚本>;标记到Javascript部分?_Javascript_Html - Fatal编程技术网

如何从<;脚本>;标记到Javascript部分?

如何从<;脚本>;标记到Javascript部分?,javascript,html,Javascript,Html,我将该脚本从HTML部分移到Javascript中,但它不起作用,并显示了该错误。有人能帮我修一下吗 Html中的ID是: <p style="font-size: 40px"><a href="https://en.wikipedia.org/wiki/Potato" target="_blank" class="heading" id="title">Potato

我将该脚本从HTML部分移到Javascript中,但它不起作用,并显示了该错误。有人能帮我修一下吗

Html中的ID是:

<p style="font-size: 40px"><a href="https://en.wikipedia.org/wiki/Potato" 
target="_blank" class="heading" id="title">Potato

<p id="e"> math </p>


错误告诉您,当此代码运行时,没有id为
的元素。当您“移动脚本”时,您可能会在该元素存在之前将其移动到文档的早期部分。最有可能的解决方法是在文档的末尾而不是开头运行代码。在文件的末尾。
var myHeader = "Click for Potatos"
document.getElementById('title').innerHTML = myHeader;
alert('Hello!')
var x = 6;
var y = 2;
var z = x + y;
document.getElementById('e').innerHTML = z;
function myFunction() {
var hour = new Date().getHours();
var greeting;
if (hour < 24) {
greeting = "Less than 24";} 
else {
greeting = "greater than 24";}
document.getElementById("button").innerHTML = greeting; 
}
var person = {
firstName: "Justin",
lastName: "Chen",
age: "17",
eyeColor: "Brown"};
document.getElementById("name").innerHTML = person.firstName + " " + 
person.lastName + " has " + person.eyeColor + " eyes and is " + person.age 
+ " years old.";
var things = ["Is", " that", " hard?", "eek"];
things[0] = "Was"
document.getElementById("ting").innerHTML = things;
things.pop();
document.getElementById('ting').innerHTML = things;
                    Info
                </a> </p>