首页 > Web开发 > 详细

前端HTML初学心得

时间:2020-03-05 16:22:55      阅读:93      评论:0      收藏:0      [点我收藏+]

今天学习了一下HTML 中JavaScript内容,觉得初学者需要注意下面几点:

  1. 函数好像都是放在script标签内,css样式<style><style>,,中间的样式格式为标签{}大括号里面写样式。还有一种写法[]里面写type

    <style type="text/css" >
    table{
    margin: 20px auto;
    border: 5px solid orange;
    }
    td{
    height: 40px;
    line-height: 40px;
    padding: 5px;
    width: 200px;
    background: rgba(100,20,10,0.3);
    text-align: right;
    }
    select,input{
    width:200px;
    height:40px;
    font-size:18px;
    }
    [type=radio]{
    width: 30px;
    height: 30px;
    }
    [type=submit],[type=reset]{
    width: 140px;
    border-radius: 30px;
    font-size: 20px;
    outline: none;

    }
    td:first-child{
    width: 100px;s
    }
    </style>

  2. 上面全部为样式。

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    <script>
    function displayDate(){
    document.getElementById("demo").innerHTML=Date();
    }
    </script>
    </head>
    <body background-color: rgba(254,219,207,0.5);>
    <style type="text/css" >
    table{
    margin: 20px auto;
    border: 5px solid orange;
    }
    td{
    height: 40px;
    line-height: 40px;
    padding: 5px;
    width: 200px;
    background: rgba(100,20,10,0.3);
    text-align: right;
    }
    select,input{
    width:200px;
    height:40px;
    font-size:18px;
    }
    [type=radio]{
    width: 30px;
    height: 30px;
    }
    [type=submit],[type=reset]{
    width: 140px;
    border-radius: 30px;
    font-size: 20px;
    outline: none;

    }
    td:first-child{
    width: 100px;s
    }
    </style>

    <table>
    <tr>
    <td>用户名:</td>
    <td>
    <input type="text" id="str1">
    </td>
    </tr>
    <tr>
    <td>
    联系电话:
    </td>
    <td>
    <input type="text" id="str2">
    </td>
    </tr><tr>
    <td>
    密码:
    </td>
    <td>
    <input type="password" id="str3">
    </td>
    </tr><tr>
    <td>
    确认密码:
    </td>
    <td>
    <input type="password" id="str4" onblur="check()">
    </td>
    </tr><tr>
    <td>
    性别:
    </td>
    <td>
    <input type="radio" name="sex" id="sex">男
    <input type="radio" name="sex" id="sex">女
    </td>
    </tr>
    </tr><tr>
    <td>
    学历:
    </td>
    <td>
    <select id="select">
    <option value="高中">高中</option>
    <option value="初中">初中</option>
    <option value="小学">小学</option>
    </select>
    </td>
    </tr>
    </tr><tr>
    <td colspan="2">
    <input type="submit" id="btn1" >
    <input type="reset" id="bt2" value="重置" onclick="cs()">
    </td>

    </tr>
    </table>

    </body>
    <script type="text/javascript">
    function $(id){
    return document.getElementById(id)

    }
    function check(){
    var boo=$(‘str3‘).value==$(‘str4‘).value
    if (boo) {
    return true
    }else{
    alert("密码错误!")
    }
    }
    function cs(){
    var str=‘‘
    str+="\n用户名:"
    str+=$(‘str1‘).value;
    str+="\n联系电话:"
    str+=$(‘str2‘).value;
    str+="\n性别:";
    str+=$(‘sex‘).checked?‘男‘:‘女‘;
    str+="\n学历:"
    str+=$(‘select‘).value;
    alert("用户信息:\n"+str);
    }
    </script>

    }
    </html>

  3. 元素尽量都要有一个ID,可以使这个元素的属性成为动态内容。

前端HTML初学心得

原文:https://www.cnblogs.com/hbeksk/p/12420819.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!