HTML表单的编写

2025-10-10 21:33:38

1、打开PyCharm开发工具,创建‘form.html’文件,编写代码如下:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <form>        <input type="text">        <input type="submit">    </form></head><body></body></html>

这是一个最简单的表单,只有<form>标签包围才是表单

HTML表单的编写

2、点击右上角浏览器可以查看效果,input标签通过type属性,决定输出的样式

HTML表单的编写

3、丰富一下表单,指定提交位置form标签属性是action,method是提交方式,代码如下:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <form action="" method="post">        <input type="text">                    <input type="submit" value="提交查询">            <input type="reset" value="清空重置">                    </form></head><body></body></html>

HTML表单的编写

4、再添加单选按钮,注意单选是只有一个被选中,所以一定要有name属性代码如下:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <form action="" method="post">        <input type="text">                            <input type="radio" name="gender">男            <input type="radio" name="gender">女                            <input type="submit" value="提交查询">            <input type="reset" value="清空重置">            </form></head><body></body></html>

HTML表单的编写

5、在添加一组复选框,这个是可以多选的,代码如下:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <form action="" method="post">        <input type="text">                    <input type="radio" name="gender">男            <input type="radio" name="gender">女                            <input type="checkbox">a            <input type="checkbox">b                            <input type="submit" value="提交查询">            <input type="reset" value="清空重置">            </form></head><body></body></html

HTML表单的编写

6、再添加一个下拉框select,代码如下;

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <form action="" method="post">        <input type="text">                    <input type="radio" name="gender">男            <input type="radio" name="gender">女                            <input type="checkbox">a            <input type="checkbox">b                             <select name="s1" >                <option value="sz">深圳</option>                <option value="sh">上海</option>                <option value="sc">四川</option>             </select>                            <input type="submit" value="提交查询">            <input type="reset" value="清空重置">            </form></head><body></body></html>

HTML表单的编写

7、打开右上角浏览器可以查看效果,现在稍微有点意思了。

HTML表单的编写

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢