代码使第一步:添加带有主页链接的图像和带有文档名称的 h1(如果还没有 h1)
我使用了一个引用 js 文件的 html 并且标题有一个 h1 标签(这是我想做的例外之一,因为特殊字符)
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
</head>
<body>
<h1 id="titulo">kauã</h1>
</body>
</html>
main.js:
document.write('<a href="rpg.html"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/U%2B2190.svg/25px-U%2B2190.svg.png"></a><br>');
if (document.getElementById(titulo) != null )/*se existir um não titulo... */
{var nome_do_documento = window.location.href.substring(window.location.href.lastIndexOf('/')+1); /*colete o nome do documento */
var titulo = nome_do_documento.replace('_',' ');/*troque _ por um espaço */
var titulo_pronto = titulo.replace('.html','');/*apague a extenção do nome */
document.write('<h1 id="titulo">'+ titulo_pronto +'</h1>');};/*e o nome no topo da pagina */
document.title = "PVP - " + document.getElementById(titulo).innerText;/*coloque o nome do topo da gina como titulo do html */
我期待这个步骤:
<h1 id="titulo">
<h1 id="titulo">
标签里写<tittle>
的内文我明白了:
控制台是这样说的: