网页设计html中,在文本框中输入文字,单击“确认”按钮后,将文字设置为网页标题

如题所述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<button>确认</button>
<script>

    var input = document.getElementsByTagName('input')[0];
    var button = document.getElementsByTagName('button')[0];

    button.onclick = function () {
        if(input.value.length != 0) {
            document.title = input.value;
        }
    }

</script>
</body>
</html>

温馨提示:答案为网友推荐,仅供参考
相似回答