H5_ 表单及其他新增和改良元素
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_ 表单及其他新增和改良元素的更多相关文章
- html5+css3 权威指南阅读笔记(三)---表单及其它新增和改良元素
一.新增元素及属性 1.表单内元素的form属性. html5: <form id="testForm"> <input type=text> </f ...
- html5表单及新增的改良元素
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 从零开始学 Web 之 HTML5(二)表单,多媒体新增内容,新增获取操作元素,自定义属性
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- 当一个页面中有多个form表单并且有重名的元素时,js获取指定form表单中的指定元素
有时候我们会在一个页面中写了多个form表单,碰巧多个form表单中又有相同名称的元素,而我们又不想改名字,这个时候就能用到 $("#form1 #div1").val() 好玩吧 ...
- 疯狂的表单-html5新增表单元素和属性
疯狂的表单 2015/11/27 16:44:07 从三方面来介绍html5表单的新特性 表单结构更灵活 要提交数据的控件可以布局在form标签之外,看下面的代码,表单元素可以写到form元素之外,只 ...
- html5--3.17 新增的表单重写
html5--3.17 新增的表单重写 学习要点 对form元素的属性做一个小结,对个别属性进行一点补充 重点掌握新增的表单重写 form元素的属性小结 action/method/enctype/n ...
- IT兄弟连 HTML5教程 HTML5表单 新增的表单属性1
HTML5 Input表单为<form>和<input>标签添加了几个新属性,属性如表1. 1 autocomplete属性 autocomplete属性规定form或inp ...
- 了解HTML表单之form元素
前面的话 表单是网页与用户的交互工具,由一个<form>元素作为容器构成,封装其他任何数量的表单控件,还有其他任何<body>元素里可用的标签 表单能够包含<input& ...
- 表单多文件上传样式美化 && 支持选中文件后删除相关项
开发中会经常涉及到文件上传的需求,根据业务不同的需求,有不同的文件上传情况. 有简单的单文件上传,有多文件上传,因浏览器原生的文件上传样式及功能的支持度不算太高,很多时候我们会对样式进行美化,对功能进 ...
随机推荐
- eclipse快速查看工程代码行数
1.点击要统计的项目或许文件夹,在菜单栏点击Search,然后点击File... 2.选中正则表达式(Regular expression),并在搜索文本框输入\n ;3.在文件名中输入*或*.jav ...
- 前端node.js npm i 报错Unexpected end of JSON input while parsing near
清缓存 npm cache clean --force 重新安装 npm install
- Springboot项目打包后的页面丢失问题(thymeleaf报错)
遇到的问题目前找到两种: 返回视图路径以/开头,例如 /test/hello 在thymeleaf页面中,引入的页面以/开头,例如:<footer th:replace="/index ...
- nginx unit PHP
2018-12-26 14:20:33 星期三 综述: nginx unit php 的关系: nginx -> 转发请求到 8300端口 -> unit 转发 8300 收到的请求 -& ...
- Jmeter 后置处理器JSON Extractor 提取json的多个值
- sql父子表结构,常用脚本
在实际运用中经常会创建这样的结构表Category(Id, ParentId, Name),特别是用于树形结构时(菜单树,权限树..),这种表设计自然而然地会用到递归,若是在程序中进行递归(虽然在程序 ...
- C# 模拟键盘操作SendKey(),SendKeys()
模拟键盘输入就是使用以下2个语法实现的. SendKeys.Send(string keys); //模拟汉字(文本)输入SendKeys.SendWait(string keys); //模拟按键 ...
- 指定的 CGI 应用程序遇到错误,服务器终止了该进程。
遇到这种错误只需要把这个项目的Cookies删除再重新启动就行了
- selenium笔记(1)
selenium笔记(1) 一.关闭页面:1.driver.close() 关闭当前页面2.driver.quit() 退出整个浏览器 二.定位元素:1.find_element_by_id: 根据i ...
- js中的传值和传引用,判断两个数组是否相等
所谓js的中的传值,其实也就是说5种基本数据类型(null,undefind,boolean,number,string) 传引用也就是说的那个引用数据类型,(array和objec) 基本数据类型的 ...