侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

HTML5表单那些事

2024-05-15 星期三 / 0 评论 / 0 点赞 / 85 阅读 / 5730 字

//一般写法<form method="post" action="http://xxx:port/form"></form>//高级一点的写法:在header中添加一行base元素//base元素用

//一般写法<form method="post" action="http://xxx:port/form"></form>//高级一点的写法:在header中添加一行base元素//base元素用于设置表单数据的发送目的地,这个base元素将会影响该页面所有的相对URL,而不只是form元素。<head>    <base href="http://xxxx:port"/></head><body>    <form method="post" action="/form">            //code    </form></body>//form表单的数据编码方式,enctype属性application/x-www-form-urlencoded:在不设置enctype的情况下,默认的enctype属性,不能用于将文件上传到服务器。multipart/form-data:用于将文件上传到服务器。text/plain:chrome中使用与application/x-www-form-urlencoded方案一样,现在并没没有确定应该如何编码。总之不要用这种方式就ok。//form表单的autocomplete自动完成属性,autocomplete属性有两个值:on/off//表单禁止自动完成功能<form autocomplete="off"></form>//表单的其他元素禁止autocomplete属性,指定的元素开启自动完成属性。<form autocomplete="off">    <input type="text" autocomplete="on"//虽然form表单是off,但是input元素是on。</form>//form表单的名称定义用name,用来给表单设置一个独一无二的标识符,以便使用DOM时区区分各个表单。//name属性与全局适应id不是同一回事,后者多用于CSS选择器。<form name="fruitvote" id="fruitvote" method="post" action="http://xxxx:port/form></form>//label属性:form表单中的label元素的for属性通常和input元素的id属性一一对应,这样即可将label和input元素关联起来。//有助于屏幕阅读器和其他残障辅助技术对表单的处理。<form>    <p><label for="fave">Fruit:<input id="fave" name="fave/></label></p></form>//form表单的自动聚焦到某个input元素,浏览器一打开就会聚焦于第一个输入的元素。当多个input元素都使用autofocus属性的时候。//浏览器自动聚焦于其中的最后一个元素。<form method="post" action="http://www.baidu.com">        <p>            <label for="fave">Fruit:<input autofocus id="fave" name="fave"></label>        </p>        <p><label for="name">Name:<input id="name" name="name"></label></p>        <button>Submit</button></form>//禁用表单元素用disable//对表单元素进行编组<form>        <fieldset>            <p><label for="name"><input name="name" id="name"></label></p>            <p><label for="fave"><input name="fave"></label></p>        </fieldset>        <fieldset>            <p><label for="name"><input name="name" id="name"></label></p>            <p><label for="fave"><input name="fave"></label></p>        </fieldset></form>//为分组添加说明,使用legend元素<form>        <fieldset>            <legend>fieldset1</legend>            <p><label for="name"><input name="name" id="name"></label></p>            <p><label for="fave"><input name="fave"></label></p>        </fieldset>        <fieldset>            <legend>fieldset2</legend>            <p><label for="name"><input name="name" id="name"></label></p>            <p><label for="fave"><input name="fave"></label></p>        </fieldset>    </form>//disable属性用于fieldset元素的时候回禁用fields属性中所有的额input元素。//form表达的button按钮,button元素有3个type值:submit reset button.type为submit属性的时候又会有很多额外的属性。//form 指定按钮关联的表单//formaction 覆盖form元素的action属性//formenctype覆盖form元素enctype属性//formmethod覆盖form元素的method属性//formtarget覆盖form元素的target属性//formnovalidate是否执行客户端数据有效性的检查。//button元素type=submit的额外属性<form>        <p><label for="fave"><input id="fave" name="fave"></label></p>        <button type="submit" formaction="http://xxxx:port/form" formmethod="post"></button> </form>//button元素type=submit的form属性<form id="voteform">        <p><label for="fave"><input id="fave" name="fave"></label></p>        <button type="submit" formaction="http://xxxx:port/form" formmethod="post"></button>    </form>    <p>        <label for="name">Name:<input form="voteform" id="name" name="name"></label>    </p>    <button form="voteform" type="submit"></button>    <button form="voteform" type="reset"></button>

广告 广告

评论区