1.

 form属性

formaction属性
formmethod属性
formenctype属性
formtarget属性
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>H5form</title>
</head>
<body>
<div class="content">
<form action="" id="testfrom">
<input type="text">
</form>
<textarea name="" id="" cols="30" rows="10" form="textarea">表单内元素的form属性</textarea> <p>formaction属性:将表单提交到不同的页面</p>
<form action="server.jsp">
<input type="submit" name="s1" value="v1" formaction="s1.jsp">提交到s1
<input type="submit" name="s2" value="v2" formaction="s2.jsp">提交到s2
</form> <p>formmethod属性:对每个表单元素指定不同的提交方法</p>
<form action="">
姓名:<input type="text" name="name" formmethod="post" value="post提交方式"><br>
<input type="submit" value="get提交方式" frommethod="get">
</form> <p>formenctype属性对表单元素分别指定不同的编码方式</p>
<input type="text" formenctype="multipart/form-data"> <p>formtarget属性指定提交后在何处打开所需要加载的页面</p>
<p>autofocus属性:页面打开后,控件自动获取光标焦点(注意:一个页面只能有一个控件具有autofocus属性)</p>
<input type="text" autofocus>
</div>
<script> </script>
</body>
</html>

2.

labels属性

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>labels属性</title>
</head>
<body>
<form action="" id="testfrom">
<label for="txt_name" id="label">姓名:</label>
<input type="text" id="txt_name">
<input type="button" id="btnValidate" value="验证">
</form>
<script>
var page = {
init : function(){
this.bindEvent();
},
bindEvent : function(){
var _this = this,
button = document.getElementById('btnValidate');
button.onclick = function(){
_this.validate();
}
},
validate : function(){
var txtName = document.getElementById('txt_name'),
button = document.getElementById('btnValidate'),
form = document.getElementById('testfrom');
if(txtName.value.trim() === ''){
if(txtName.labels.length === 1){
var label=document.createElement('label');
label.setAttribute('for', 'txt_name');
form.insertBefore(label,button);
txtName.labels[1].innerHTML='请输入姓名';
txtName.labels[1].setAttribute(
"style","font-size:9px; color:red"
);
txtName.setAttribute(
"style","border:1px solid red"
)
}
}
else if(txtName.labels.length>1){
form.removeChild(txtName.labels[1]);
txtName.setAttribute(
"style","border:1px solid #ccc"
)
}
}
}
window.onload = page.init();
</script>
</body>
</html>

3.

label标签的control属性

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>label标签的control属性</title>
</head>
<body>
<p>
H5中,可以再标签label元素内部放置表单元素,并且通过该标签的control属性来访问该表单元素。
eg:通过label的control属性设置input的value
</p>
<form action="">
<label for="txt_zip" id="label">
邮编:
<input type="text" id="txt_zip" maxlength="6">
<small>请输入六位数字</small>
</label>
<input type="button" value="设置默认值" id="setValue">
</form>
<script>
var page = {
init : function(){
this.bindEvent();
},
bindEvent : function(){
var _this = this,
btn = document.getElementById('setValue');
btn.onclick = function(){
_this.setValue();
}
},
setValue : function(){
var label = document.getElementById('label'),
textbox = label.control;
textbox.value = '123456';
},
//这里直接通过获取input id设置value值。
// setValue : function(){
// var ipt = document.getElementById('txt_zip');
// ipt.value = '123456';
// }
}
window.onload = page.init();
</script>
</body>
</html>

4.

placeholder属性
autocomplete属性
pattern属性
SelectionDirection属性
复选框 indeterminate属性
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>text</title>
<style>
/* 设置placeholder样式 从 Firefox 19 开始将不再支持一个冒号的「:-moz-placeholder」伪元素,改成标准的两个冒号的「::-moz-placeholder」。今后若要兼容,开发者需要在CSS中同时书写两个伪元素。*/ /* Firefox浏览器 */
input::-moz-placeholder{
color :blue;
}
/* 更早之前的Firefox浏览器版本 */
input:-moz-placeholder{
color :blue;
}
/* webkit系列浏览器 */
input::-webkit-input-placeholder{
color :blue;
}
</style>
</head>
<body>
<p>placeholder属性</p>
<input type="text" placeholder="input me">
<p>文本框的list属性,autocomplete属性</p>
<div class="list">
text: <input type="text" name="greeting" list="grreetings" autocomplete="on">
<datalist id="grreetings" style="display: none;">
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
</datalist>
</div>
<p>pattern属性:设置正则表达式</p>
<form action="">
指定格式:<input type="text" pattern="^[0-9]{2,3}$" name=part>
<input type="submit">
</form>
<p>input,textarea的SelectionDirection:获取用户用鼠标选取文字时,该属性可以获取选取的方向</p>
<form action="">
<input type="text" name='text'>
<input type="button" value="click_me" id="SDBtn">
</form>
<div class="checkboxDiv">
<p>复选框具有选取,非选取,不明三种状态</p>
<input type="checkbox" indeterminate id='cb'>indeterminate Test
</div>
<script>
var page = {
init : function(){
this.bindEvent();
},
bindEvent : function(){
var SDBtn = document.getElementById('SDBtn');
SDBtn.onclick = function(){
var control = document.forms[1]['text'],
Direction = control.selectionDirection;
alert(Direction);
} var cb = document.getElementById('cb');
cb.indeterminate = true;
// cd.checked = true;
//检测复选框状态
if(cb.indeterminate){
alert("不明状态");
}
else if(cb.checked){
alert("选取状态");
}
else{
alert("非选取状态");
} }
}
window.onload = page.init();
</script>
</body>
</html>

H5_ 表单及其他新增和改良元素的更多相关文章

  1. html5+css3 权威指南阅读笔记(三)---表单及其它新增和改良元素

    一.新增元素及属性 1.表单内元素的form属性. html5: <form id="testForm"> <input type=text> </f ...

  2. html5表单及新增的改良元素

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. 从零开始学 Web 之 HTML5(二)表单,多媒体新增内容,新增获取操作元素,自定义属性

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  4. 当一个页面中有多个form表单并且有重名的元素时,js获取指定form表单中的指定元素

    有时候我们会在一个页面中写了多个form表单,碰巧多个form表单中又有相同名称的元素,而我们又不想改名字,这个时候就能用到 $("#form1 #div1").val() 好玩吧 ...

  5. 疯狂的表单-html5新增表单元素和属性

    疯狂的表单 2015/11/27 16:44:07 从三方面来介绍html5表单的新特性 表单结构更灵活 要提交数据的控件可以布局在form标签之外,看下面的代码,表单元素可以写到form元素之外,只 ...

  6. html5--3.17 新增的表单重写

    html5--3.17 新增的表单重写 学习要点 对form元素的属性做一个小结,对个别属性进行一点补充 重点掌握新增的表单重写 form元素的属性小结 action/method/enctype/n ...

  7. IT兄弟连 HTML5教程 HTML5表单 新增的表单属性1

    HTML5 Input表单为<form>和<input>标签添加了几个新属性,属性如表1. 1  autocomplete属性 autocomplete属性规定form或inp ...

  8. 了解HTML表单之form元素

    前面的话 表单是网页与用户的交互工具,由一个<form>元素作为容器构成,封装其他任何数量的表单控件,还有其他任何<body>元素里可用的标签 表单能够包含<input& ...

  9. 表单多文件上传样式美化 && 支持选中文件后删除相关项

    开发中会经常涉及到文件上传的需求,根据业务不同的需求,有不同的文件上传情况. 有简单的单文件上传,有多文件上传,因浏览器原生的文件上传样式及功能的支持度不算太高,很多时候我们会对样式进行美化,对功能进 ...

随机推荐

  1. MySQL中使用group_concat()函数数据字符过长报错的问题解决方法

    最近在办公软件项目,在开发权限指标遇到一个问题:我们系统的一些逻辑处理是用存储过程实现的,但是有一天客户反馈说权限指标分配报错,查了分配的权限数据牵扯到的数据权限基础资源,没有问题.权限指标分配的存储 ...

  2. 通过scrollTop,使子元素滚动至指定位置

    想实现这样的一个功能,点击子元素,让元素滚动至指定位置,怎么实现呢? 在代码实现之前,先了解下相关关键点. 1.scrollHeight 属性 通过 scrollHeight 属性可获得子元素的滚动高 ...

  3. 「JavaScript面向对象编程指南」对象

    对象的属性名可加上引号,下面三行代码所定义的内容是完全相同的 var hero = { occupation : 1 }; var hero = { "occupation" : ...

  4. # 20175333曹雅坤《Java程序设计》第四周学习总结

    教材学习内容总结 第五章:子类与继承 5.1子类与父类:关键字extends 5.2子类的继承性:如果子类与父类在一个包中,除了private其他都可以继承:如果不在一个包中,则private和友好都 ...

  5. hihocoder 1176

    hihocoder 1176 题意:N,M.分别表示岛屿数量和木桥数量,一笔画 分析:欧拉路问题(给定无孤立结点图G,若存在一条路,经过图中每边一次且仅一次,该条路称为欧拉路) 欧拉路的条件 一个无向 ...

  6. 资产信息之收集资产代码流程,API的一个认证,数据库表的设计

    收集资产代码流程 1.起初我们些的代码是面条式的一堆的逻辑判断.   后来通过了不断的优化升级实现了一个3种方案都支持的CMDB系统,我们用哪种方案只需要在配置文件里修改一下设置就行了.   同时我们 ...

  7. docker-elk装IK自定义分词库

    本人的elasticsearch是docker环境下运行 运行elasticsearch的容器,通过docker命令:docker exec -it 955e8d32d4a9 /bin/bash 进入 ...

  8. 导出pip安装的所有放入一个文件中,并把通过这个安装所有的包

    导出pip安装的所有的包: pip freeze > piplist.txt 在新的环境中安装导出的包 pip install -r piplist.txt

  9. 软件工程---作业(one)

    (1) 回顾你过去将近3年的学习经历 1.1 有序列表项一当初你报考的时候,是真正喜欢计算机这个专业吗? 自己填写来着,对这个专业也不是特别了解:导致后续学习很差 1.2 有序列表项二你现在后悔选择了 ...

  10. 记录MYSQL中SQL语句的一个坑.

    MYSQL5.7 假设我们有一个表 : h_member_cards_my  (ID, WXOPEN_ID) 表中有一条记录如下: 理论上第二个SQL应当是可以查询得到一条数据的, 结果却为 Empt ...