Home > Web Front-end > JS Tutorial > How to control the title and add information through Js code

How to control the title and add information through Js code

一个新手
Release: 2017-10-10 10:02:11
Original
1674 people have browsed it


  • Achieve the effect

    • showTitle: When the display title button is clicked, all The title is displayed

    • hideTitle: When the hide title button is clicked, all titles are hidden

    • addCity: When the add city button is clicked , a new city name

<!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title></title>
    <script>
        //        function showTitle() {
        //            var titleElement = document.getElementById("title");
        //            titleElement.style.display = "block";
        //        }
        //
        //        function hideTitle() {
        //            var titleElement = document.getElementById("title");
        //            titleElement.style.display = "none";
        //        }

        function addCity() {
            var newElement = document.createElement("li"); // <li></li>
            var textNode = document.createTextNode("重庆"); // 重庆
            newElement.appendChild(textNode); // <li>重庆</li>

            document.getElementById("city").appendChild(newElement);
        }    </script></head><body><h3 id="title" style="display: block">八维学院</h3><h3 id="title222" style="display: block">八维学院222</h3><p>选择城市</p><ul id="city">
    <li>北京</li>
    <li id="city_2">上海</li>
    <li>天津</li></ul><input type="button" onclick="showTitle()" value="显示标题"/><input type="button" onclick="hideTitle()" value="隐藏标题"/><input type="button" onclick="addCity()" value="添加城市"/><script>
    /*window.document.getElementById("title");*/
    var arr = document.getElementsByTagName("h3");
    console.log(arr[0]);
    console.log(arr[1]);</script></body></html>
Copy after login
will be created under the original city list.

The above is the detailed content of How to control the title and add information through Js code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template