Html提高——HTML5 新增的 input 类型

1、新增input的类型:

6d15ba72ae3e5a7c4e590b02a3f622c2.png

2、各类input属性代码展示与效果图

2.1、required属性

文本框一定要被填写,否则在点击提交的时候会提示需要被填写

代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML5新增表单属性</title>
</head>

<body>
    <form action="">
        <input type="search" name="sear" id="" required="required">
        <input type="submit" value="提交">
    </form>

</body>

</html>

效果图:

1b4c494ff30a858e54ad5d8d1d4b1324.png

2.2、placeholder属性

会在文本框里面提示一些文本,当在文本框里输入任意内容后,提示文本会消失

代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML5新增表单属性</title>
    <style>
        input::placeholder {
            color: blue;
        }
    </style>
</head>

<body>
    <form action="">
        <input type="search" name="sear" id="" placeholder="迪幻">
        <input type="submit" value="提交">
    </form>

</body>

</html>

效果图:

c7633b1b55c398f863ac54c56d3acfae.png

c21fcc9d351b0885c0a8cc1a37e1acd5.png

2.3、autofocus属性

当打开页面的时候,会将光标自动聚焦在文本框

代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML5新增表单属性</title>
</head>

<body>
    <form action="">
        <input type="search" name="sear" id="" autofocus="autofocus">
        <input type="submit" value="提交">
    </form>

</body>

</html>

效果图:ba36c4b1cffcc4bd45babdbdeda2e06e.png

2.4、autocomplete属性

当文本框里的内容提交成功后,下次填写可以直接选中以前填写提交过的内容

代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML5新增表单属性</title>
</head>

<body>
    <form action="">
        <input type="search" name="sear" id="" autocomplete="on">
        <input type="submit" value="提交">
    </form>

</body>

</html>

效果图:

bbc339b3ba8972fdc5c7ff57c8ee7aed.png

2.5、mutipile属性

可以同时选中多个文件

代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML5新增表单属性</title>
</head>

<body>
    <form action="">
        <input type="file" name="" id="" multiple="multiple">
        <input type="submit" value="提交">
    </form>

</body>

</html>

效果图:

55322e637d00d3646ff7bfcbee65c80f.png

 

作者:迪幻

物联沃分享整理
物联沃-IOTWORD物联网 » Html提高——HTML5 新增的 input 类型

发表回复