javascript中title属性的用法是什么
生活随笔
收集整理的這篇文章主要介紹了
javascript中title属性的用法是什么
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在javascript中,title屬性用于設置或返回當前文檔的標題,即HTML title元素中的文本內容;直接使用“document.title”語句即可返回標題,使用“document.title="需要設置的值"”語句即可修改標題。
本教程操作環境:windows7系統、javascript1.8.5版、Dell G3電腦。
在javascript中,title屬性用于設置或返回當前文檔的標題(HTML title元素中的文本內容)。
語法:
返回文檔標題
document.title
設置(修改)文檔標題
document.title="需要設置的值"
示例:
<!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>
【相關推薦:javascript學習教程】
總結
以上是生活随笔為你收集整理的javascript中title属性的用法是什么的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Css 特殊或不常用属性
- 下一篇: form、document.all[].