[英]How to run a JS Function in HTML5
Hello i have a question.你好我有一个问题。
How can I run my function "title()" in HTML?如何在 HTML 中运行我的 function“title()”?
I have created a "main.js" File, in there, there is following Code:我创建了一个“main.js”文件,其中有以下代码:
"use strict";
document.addEventListener("DOMContentLoaded", function() {
let newScript = document.createElement("script");
newScript.src = "javascript/head.js";
let heads = document.getElementsByTagName("head")[0];
console.log(heads)
heads.prepend(newScript);
});
in the "main.js" File load an another Script which is called "head.js" and here is the Code of this File:在“main.js”文件中加载另一个名为“head.js”的脚本,这是该文件的代码:
function title(titleName) {
let title = document.createElement("title");
document.title = titleName;
document.head.appendChild(title);
}
Maybye you need my HTML Code:也许你需要我的 HTML 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="javascript/main.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script> title("Framework"); </script>
</head>
<body>
</body>
</html>
in head.js
add:在
head.js
中添加:
window.addEventListener("load", () => title("my desired title name"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.