HTML DOM title 对象
htmlweb developmentfront end technology更新于 2024/3/19 8:44:17
HTML 中的 HTML DOM 标题对象代表 <title> 元素。
创建 <title> 元素
var titleObject = document.createElement(“TITLE”)
此处,“titleObject” 可以具有以下属性 −
| 属性 | 描述 |
|---|---|
| text | 它设置/返回 <title> 的值。文档元素 |
让我们看一个title text属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<title id="titleSelect">HTML DOM Title text</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend id="legendSelect"></legend>
<input type="button" onclick="getTitleText()" value="What's the title of document?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var legendSelect = document.getElementById("legendSelect");
var titleSelect = document.getElementById("titleSelect");
function getTitleText() {
divDisplay.textContent = 'Title of document: '+titleSelect.text;
legendSelect.textContent = titleSelect.text.split(' ').join('-');
}
</script>
</body>
</html>
输出
点击"文档的标题是什么?"按钮之前 −

点击"文档的标题是什么?"按钮之后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

