我是JS的新手,并从JON DUCKETT的JAVASCRIPT和JQUERY书中学习。
我对有关 document.title 使用情况
的问题感到震惊我编写了有关如何使用文档对象的代码。
除标题
之外,所有属性和方法都可以使用我附上了代码,请看一下并帮助我获取 title 财产。
代码如下:
<!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的声誉才能发布必须编写此代码的图像。
答案 0 :(得分:0)
您的代码已打开,只是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>
答案 1 :(得分:0)
您的代码实际上正在工作。点击下面的运行代码按钮以实时查看它:
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
的内容时,编写a = a + b
只是一种简写。没有更多,没有更多。 :)
答案 2 :(得分:-1)
plz检查所有代码 给定好人
<!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>