我尝试使用该代码但它不起作用?
<html>
<head>
<script>
document.getElementbyId("title1").value="MyTitle";
</script>
<title id="title1"> </title>
</head>
<body>
</body>
</html>
javascript中是否有任何方法?
答案 0 :(得分:1)
您可以使用document.title
<!DOCTYPE html>
<html>
<head>
<title id="title1"> </title>
<!-- note `<script>` element after `<title>` element -->
<script>
document.title = "MyTitle";
</script>
</head>
<body>
</body>
</html>
答案 1 :(得分:1)
document.title
请参阅document.title
<html>
<head>
<title id="title1"></title>
</head>
<body>
</body>
<script>
document.title = "MyTitle";
</script>
</html>
<html>
<head>
<title id="title1"></title>
</head>
<body>
</body>
<script>
document.getElementbyId("title1").value = "MyTitle";
</script>
</html>