Home >Web Front-end >Front-end Q&A >What is the usage of title attribute in javascript
In javascript, the title attribute is used to set or return the title of the current document, that is, the text content in the HTML title element; directly use the "document.title" statement to return the title, use "document.title= "The value that needs to be set" statement can modify the title.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, the title attribute is used to set or return the title of the current document (the text content in the HTML title element).
Syntax:
Return document title
document.title
Settings ( Modify) Document title
document.title="需要设置的值"
Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>旧文档标题</title> </head> <body> <input type="button" value="获取标题" id="btn1" /> <input type="button" value="修改标题" id="btn2" /> <script> function my(id) { return document.getElementById(id); } my("btn1").onclick = function() { var title = document.title; alert(title); } my("btn2").onclick = function() { document.title = "新文档标题"; var title = document.title; alert("修改成功,新值为: " + title); } </script> </body> </html>##[Related recommendations:
The above is the detailed content of What is the usage of title attribute in javascript. For more information, please follow other related articles on the PHP Chinese website!