document.title 个问题 Javascript
document.title problems in Javascript
我是 JS 的新手,正在学习 JON DUCKETT 的 JAVASCRIPT 和 JQUERY 一本书。
我对 document.title 用法的问题感到震惊
我写了一个关于如何使用文档的代码 objects。
每个 属性 和方法都有效,除了标题
我附上了一个代码,请看一下并帮助我如何获得标题
属性 工作中。
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
</head>
<body>
<h1>THANOS</h1>
<div id="tony"></div>
</body>
<script>
var lord = "<p> The title of the page is :" + document.title + "</p>";
lord += "<p>address of the page is : " + document.URL + "</p>";
lord += " <p>Last modified is : " + document.lastModified + "</p>";
var man = document.getElementById("tony");
man.innerHTML = lord;
</script>
</html>
输出:
灭霸
The title of the page is :
address of the page is : https://fiddle.jshell.net/_display/
Last modified is : 07/14/2018 10:28:57
为什么不显示标题?
代码中的+=是什么意思请大家帮忙
抱歉,我没有 10 到 post 图像的声誉我必须编写此代码。
您的代码已打开,只是 jsfiddle 将标题设置为空。
见 jsbin
http://jsbin.com/yorivec/edit?html,output
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
</head>
<body>
<h1>THANOS</h1>
<div id="tony"></div>
</body>
<script>
var lord = "<p> The title of the page is :" + document.title + "</p>";
lord += "<p>address of the page is : " + document.URL + "</p>";
lord += " <p>Last modified is : " + document.lastModified + "</p>";
var man = document.getElementById("tony");
man.innerHTML = lord;
</script>
</html>
您的代码确实有效。点击下面的 运行 代码 按钮即可实时观看:
var lord = "<p> The title of the page is :" + document.title + "</p>";
lord += "<p>address of the page is : " + document.URL + "</p>";
lord += " <p>Last modified is : " + document.lastModified + "</p>";
var man = document.getElementById("tony");
man.innerHTML = lord;
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
</head>
<body>
<h1>THANOS</h1>
<div id="tony"></div>
</body>
</html>
而且,当我们用任何编程语言(不仅仅是JavaScript)编写类似a += b
的东西时,它只是一个shorthand来编写a = a + b
。仅此而已。 :)
请检查所有代码
给你好
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
<script>
function myFunction() {
var d = new Date();
document.getElementById("time").innerHTML="last update:"+d;
document.getElementById("url").innerHTML="url:"+window.location.href+".....current page....."+window.location.pathname+".........websitename......"+window.location.hostname;
document.getElementById("title").innerHTML="Title:"+document.title;
}
</script>
<style>
body {
font-family: Calibri, sans-serif;
font-size:15px;
line-height:1.5;
padding:0;
margin:0;
background-color: #f4f4f4;
}
</style>
</head>
<body>
<h1 id="title">This is a Headhing</h1>
<p id="url">This is a paragraph.</p>
<p id="time">This is a paragraph.</p>
<button onclick="myFunction()">Try it</button>
</body>
</html>
我是 JS 的新手,正在学习 JON DUCKETT 的 JAVASCRIPT 和 JQUERY 一本书。
我对 document.title 用法的问题感到震惊
我写了一个关于如何使用文档的代码 objects。
每个 属性 和方法都有效,除了标题
我附上了一个代码,请看一下并帮助我如何获得标题 属性 工作中。
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
</head>
<body>
<h1>THANOS</h1>
<div id="tony"></div>
</body>
<script>
var lord = "<p> The title of the page is :" + document.title + "</p>";
lord += "<p>address of the page is : " + document.URL + "</p>";
lord += " <p>Last modified is : " + document.lastModified + "</p>";
var man = document.getElementById("tony");
man.innerHTML = lord;
</script>
</html>
输出: 灭霸
The title of the page is :
address of the page is : https://fiddle.jshell.net/_display/
Last modified is : 07/14/2018 10:28:57
为什么不显示标题?
代码中的+=是什么意思请大家帮忙
抱歉,我没有 10 到 post 图像的声誉我必须编写此代码。
您的代码已打开,只是 jsfiddle 将标题设置为空。 见 jsbin http://jsbin.com/yorivec/edit?html,output
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
</head>
<body>
<h1>THANOS</h1>
<div id="tony"></div>
</body>
<script>
var lord = "<p> The title of the page is :" + document.title + "</p>";
lord += "<p>address of the page is : " + document.URL + "</p>";
lord += " <p>Last modified is : " + document.lastModified + "</p>";
var man = document.getElementById("tony");
man.innerHTML = lord;
</script>
</html>
您的代码确实有效。点击下面的 运行 代码 按钮即可实时观看:
var lord = "<p> The title of the page is :" + document.title + "</p>";
lord += "<p>address of the page is : " + document.URL + "</p>";
lord += " <p>Last modified is : " + document.lastModified + "</p>";
var man = document.getElementById("tony");
man.innerHTML = lord;
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
</head>
<body>
<h1>THANOS</h1>
<div id="tony"></div>
</body>
</html>
而且,当我们用任何编程语言(不仅仅是JavaScript)编写类似a += b
的东西时,它只是一个shorthand来编写a = a + b
。仅此而已。 :)
请检查所有代码 给你好
<!DOCTYPE html>
<html>
<head>
<title>Hammer</title>
<script>
function myFunction() {
var d = new Date();
document.getElementById("time").innerHTML="last update:"+d;
document.getElementById("url").innerHTML="url:"+window.location.href+".....current page....."+window.location.pathname+".........websitename......"+window.location.hostname;
document.getElementById("title").innerHTML="Title:"+document.title;
}
</script>
<style>
body {
font-family: Calibri, sans-serif;
font-size:15px;
line-height:1.5;
padding:0;
margin:0;
background-color: #f4f4f4;
}
</style>
</head>
<body>
<h1 id="title">This is a Headhing</h1>
<p id="url">This is a paragraph.</p>
<p id="time">This is a paragraph.</p>
<button onclick="myFunction()">Try it</button>
</body>
</html>