Home > Web Front-end > HTML Tutorial > What is the innerHTML property? Usage of innerHTML attribute

What is the innerHTML property? Usage of innerHTML attribute

不言
Release: 2018-08-06 16:43:35
Original
10373 people have browsed it

What is the use of the innerHTML attribute? This article introduces to you what is the innerHTML attribute? The usage of i and nnerHTML attributes has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

innerHTML attribute

The inner attribute can return or set the content in the element

For example,

  • aaaaa
  • Access li.innerHTML to get the content aaaaa

    You can also assign content to the tag

    Example: Get the current time (refreshed every second)

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="times"></div>
        <li>aaaaa</li>
    </body>
        <script type="text/javascript">
            function gettimes(){ 
            var date1 = new Date();//创建时间对象
            var date2 = date1.toLocaleString();//使用格式为年月日时分秒
            var div1 = document.getElementById(&#39;times&#39;);//获取div格子
            div1.innerHTML = date2;//向html中写内容
     
            }
     
            setInterval("gettimes();",1000);//"js代码",时间
        </script>
    </html>
    Copy after login

    Recommended related articles:

    What is responsive layout? Implementation of html responsive layout

    #What are the common types of html layout? Analysis of the three layout characteristics of html

    The above is the detailed content of What is the innerHTML property? Usage of innerHTML attribute. 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