• HTML5学习总结——HTML5新增属性与表单元素


    一HTML5新增属性

    1.1contcxtmcnu

    contextmenu的作用是指定右键菜单。

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <div id="div1" style="height:900px; background: lightgreen;" contextmenu="menuShare">
            </div>
            <menu id="menuShare" type="context">
                <menuitem label="分享到QQ空间" onclick="alert('QQ');"></menuitem>
                <menuitem label="分享到朋友圈" onclick="alert('朋友圈');"></menuitem>
                <menuitem label="分享到微博" onclick="alert('微博');"></menuitem>
            </menu>
        </body>
    </html>

    运行效果:

    1.2、data-*

    data-*属性能让用户自定义属性的方式来存储数据
    <span data-order-amount=100></span>
    取值:
    getAttribute('data-order-amount')
    dataset.orderAmount
    jQuery中的data()方法同样可以访问

    使用jQuery与javascript添加与获取data属性示例:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>data-*</title>
            <script src="js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
        </head>
        <body>
            <h2>data-*</h2>
            <div id="div1" data-student-name="Tom" data-stu='{"a":1,"b":2}'></div>
            <button onclick="addData()">添加数据</button>
            <button onclick="getData()">获取数据</button>
            <script type="text/javascript">
                var div1=document.getElementById("div1");
                function addData()
                {
                    //给div1添加属性data-student-name,值为rose
                    div1.setAttribute("data-student-name","Rose");
                    $("#div1").data("stu-mark","99分");
                }
                function getData()
                {
                    //原生JavaScript
                    //alert(div1.getAttribute("data-student-name"));
                    
                    //jQuery
                    alert($("#div1").data("student-name"));
                    alert($("#div1").data("stu").a);
                    alert($("#div1").data("stu-mark"));
                }
                
                
                var x="{a:1}";
                alert(eval("("+x+")").a);
            </script>
        </body>
    </html>

    运行效果:

    1.3.表单元素

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title>HTML5新的表单元素</title>
        </head>
    
        <body>
            <h2>HTML5新的表单元素</h2>
            <form>
                <p>
                    <label>姓名:</label>
                    <input type="text" required="required"/>
                </p>
                <p>
                    <label>相片:</label>
                    <input type="file" multiple="multiple"/>
                </p>
                <p>
                    <label>帐号:</label>
                    <input type="text" name="username" autocomplete="on" required="required" pattern="^[0-9a-zA-Z]{6,16}$" />请输入a-zA-Z0-9且长度6-16位的字符
                </p>
                <p>
                    <label>邮箱:</label>
                    <input type="email" name="mail" id="mail" value="" placeholder="请输入邮箱"/>
                </p>
                <p>
                    <label>博客:</label>
                    <input type="url" name="blog" id="blog" value="" required="required" autofocus="autofocus"/>
                </p>
                <p>
                    <label>生日:</label>
                    <input type="date">
                </p>
                <p>
                    <label>身高:</label>
                    <input type="number" max="226" min="80" step="10" value="170" />
                </p>
                <p>
                    <label>肤色:</label>
                    <input type="color" onchange="document.bgColor=this.value" />
                </p>
                <p>
                    <label>体重:</label>
                    <input type="range" max="500" min="30" step="5" value="65" onchange="showValue(this.value)"/>
                    <span id="rangeValue"></span>
                </p>
                <button formnovalidate="formnovalidate">提交</button>
                <script type="text/javascript">
                    function showValue(val){
                        document.getElementById("rangeValue").innerHTML=val;
                    }
                </script>
            </form>
        </body>
    
    </html>

    运行效果:

    1.4HTML5特殊超链接:

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
    
        <body>
            <a href='sms:15919218899'>短信</a>
            <br />
            <a href="tel:15919218899">电话</a>
            <br />
            <a href="mailto:99519876@qq.com">邮件</a>
            <br/>
            <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=99518888&site=qq&menu=yes" alt="点击这里给我发消息" title="点击这里给我发消息">QQ客服</a>
            <br />
            <a href="http://map.baidu.com/mobile/webapp/search/search/qt=s&wd=%E7%8F%A0%E6%B5%B7%E6%B8%AF&c=348&searchFlag=bigBox&version=5&exptype=dep/vt=map/?fromhash=1">地图</a>
            <br />
            <a href="http://map.baidu.com/mobile/webapp/index/index#place/detail/qt=ninf&wd=%E5%8D%97%E6%96%B9IT%E5%AD%A6%E9%99%A2&c=140&searchFlag=bigBox&version=5&exptype=dep&src_from=webapp_all_bigbox&sug_forward=&src=0&uid=717b5c621070ee955d0d0270&industry=education&qid=3767972802907606580/showall=1&pos=0&da_ref=listclk&da_qrtp=11&da_adtp=&da_log=sampid%3A3_eno%3A206_adnum%3A0_sid%3A9712246999610050_from%3Awebappmap_exptype%3Aurl_query%3A%E5%8D%97%E6%96%B9IT%E5%AD%A6%E9%99%A2_adids%3A_killnum%3A0_userids%3A&da_adquery=%E5%8D%97%E6%96%B9it%E5%AD%A6%E9%99%A2&da_adtitle=%E5%8D%97%E6%96%B9IT%E5%AD%A6%E9%99%A2&da_adindus=%E6%95%99%E8%82%B2%E5%9F%B9%E8%AE%AD%3B%E9%AB%98%E7%AD%89%E9%99%A2%E6%A0%A1&detail_from=list%26pos%3D0%26ad_page_logs%3D%26semStatType%3Dlist&vt=map">IT学院</a>
            <br />
            <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a></div>
    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"1","bdSize":"32"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
        </body>
    
    </html>

    运行效果:

  • 相关阅读:
    【树转数组】poj1195
    sigsuspend sigprocmask函数的用法
    [javascirpt] Regex
    [Angular 2] Passing data to components with 'properties'
    [TypeScript] Inheritance
    [Angular 2] Pipes with Multiple Parameters
    [Angular 2] Create a simple search Pipe
    [Angular 2] Pipe Purity
    [Angular 2] Exposing component properties to the template
    [Angular 2] ng-model and ng-for with Select and Option elements
  • 原文地址:https://www.cnblogs.com/zhangyongl/p/6102077.html
Copyright © 2020-2023  润新知