表单相关
一、HTML相关
1、input常用类型
2、输入框
<iput type="text" name="名称" size="显示宽度" maxlength="最大宽度" value="值" required autofocus/>3、单选按钮
<input type="radio" name="名称" value="值" checked="checked"/>4、列表框
A、菜单式
B、列表式
<select name="名称" size="高度" multiple="multiple">允许多选一组列表式的列表框,必须命名为数组形式。
5、readonly和disabled的区别
6、点击文字,选中radio
除了js实现,我们也可以用lable标签的for属性来实现。
7、如何删除input自动记忆的信息?
autocomplete = off8、取消input在ios下,输入的时候英文首字母的默认大写
<input autocapitalize="off" autocorrect="off" />9、用div模拟textarea
<div contenteditable=true>这是一个假文本域</div>二、CSS相关
1、取消默认外观
input, select, button, textarea{ -webkit-appearance:none; appearance: none; outline:none; }2、禁用pc端表单输入框默认清除按钮
input[type="text"]::-ms-clear, input[type="tel"]::-ms-clear, input[type="number"]::-ms-clear { display:none; }3、禁用select默认箭头
select::-ms-expand { display:none; }4、禁用radio和checkbox默认样式
input[type="radio"]::-ms-check, input[type="checkbox"]::-ms-check { display:none; }5、android上去掉语音输入按钮
input::-webkit-input-speech-button {display: none}6、给输入框的placeholder设置颜色
::-webkit-input-placeholder { /* WebKit browsers */color: #999; } :-moz-placeholder { /* Mozilla Firefox 4 to 18 */color: #999; } ::-moz-placeholder { /* Mozilla Firefox 19+ */color: #999; } :-ms-input-placeholder { /* Internet Explorer 10+ */color: #999; } input:focus::-webkit-input-placeholder{ color:#999; }7、input[type="file"]样式美化
opacity: 0; filter: alpha(opacity=0);把文件控件的opacity设置为0,然后用div包裹,对div设置样式即可。
8、input[type="search"]搜索框右侧小图标如何美化?
input[type="search"]::-webkit-search-cancel-button{ -webkit-appearance: none;height: 15px; width: 15px;border-radius: 8px;background:url("images/searchicon.png") no-repeat 0 0;background-size: 15px 15px; }9、日期选择组件美化
input[type="date"]::-webkit-calendar-picker-indicator {display: none; }10、textarea禁止拖动
resize: none;11、禁用number的箭头
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {-webkit-appearance: none; } input[type="number"]{-moz-appearance: textfield; }三、JS相关
1、给input赋值的两种方式
2、选中checkbox
A、dom_ckb.checked = true; 可以直接在视图上看到checkbox已经勾选,但是标签属性并没有变化。 B、dom_ckb.setAttribute('checked',false); 可以看到标签属性有checked="false",但视图没有任何变化。综上,dom_ckb.checked和dom_ckb.setAttribute('checked',false)没有关系,也互不影响。
3、让checkbox失效
A、dom_ckb.disabled = true; 可以直接在视图上看到checkbox已经失效,但是标签属性并没有变化。 B、dom_ckb.setAttribute('disabled',false); 可以看到标签属性有disabled="false",但视图没有任何变化,checkbox依旧不可以点击。综上,要用dom_ckb.disabled = true;来控制激活还是失效。
4、提交表单
用form写表单,js里面写form提交,如果关键字出现空格,请求的URL会出现加号;
用div写表单,js里面写按钮提交或者键盘提交,如果关键字出现空格,请求的URL会把空格编码%20;
转载于:https://www.cnblogs.com/camille666/p/form.html
总结
- 上一篇: [JZOJ P1291] [DP]添加括
- 下一篇: 技能CDDemo(点击鼠标左键实现技能界