0

我是 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 的声誉来发布我必须编写此代码的图像。

4

3 回答 3

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>

于 2018-07-14T05:32:13.317 回答
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>

a += b而且,当我们用任何编程语言(不仅仅是 JavaScript)编写类似的东西时,它只是编写a = a + b. 不多也不少。:)

于 2018-07-14T05:36:59.123 回答
-1

请检查所有给定的代码 bello

<!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>

于 2018-07-14T06:30:19.337 回答