• 【HTML5】元素<script>与<noscript>的使用


    功能描述

    在新建的页面中增加一个文本框“txtContent”和一个按钮“请点击我”;当单击按钮时。通过页面中加入的JavaScript脚本获取为文本框中的内容,并显示在页面上。

    实现代码

    HTML

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>脚本元素的使用</title>
        <link href="css/css1.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" async="true">
            function Btn_Click(){
                var strTxt = document.getElementById("txtContent").value;
                var strDiv = document.getElementById("divShow");
                strDiv.style.display="block";
                strDiv.innerHTML="您输入的字符是:"+strTxt;
            }
        </script>
        <noscript>您的浏览器不支持javascript</noscript>
    </head>
    <body>
    <input type="text" id="txtContent" class="inputtxt"/>
    <input type="button" value="请点击我" class="inputbtn" onclick="Btn_Click();"/>
    <div id = "divShow" class="divShow"></div>
    </body>
    </html>
    View Code

    CSS

    @charset "utf-8"
    /*CSS Document*/
    body{
    	font-size:14px;
    }
    .inputbtn {
    	border:solid 1px #ccc;
    	background-color:#eee;
    	line-height:18px;
    	font-size:12px;
    }
    .inputtxt{
    	border:solid 1px #ccc;
    	line-height:18px;
    	font-size:12px;
    }
    .divShow{
    	font-size:18px;
    	font-weight:blod;
    	line-height:28px;
    	background:green;
    }
    View Code

    页面效果

    image

    在本实例的<script>元素中,设置async属性设置的值为true,即允许脚本在页面解析时异步执行,在很大程度上加速页面加载速度。

  • 相关阅读:
    1.两数之和 力扣,水题
    525.连续数组 力扣 (前缀和)
    [LeetCode]56. Group Anagrams变位词分组
    界面布局注意(一)
    docker常用命令
    docker常用批量操作命令
    Golang package之math/rand
    (三)虚拟机与Linux新尝试——20155306白皎
    洛谷 P1383 codevs 3333 高级打字机
    BZOJ 1013 cogs 1845 [JSOI2008]球形空间产生器sphere
  • 原文地址:https://www.cnblogs.com/OliverQin/p/7607795.html
Copyright © 2020-2023  润新知