Form表单之input文本框操作
来源:互联网 发布:淘宝怎么删除空间图集 编辑:程序博客网 时间:2024/06/09 21:27
input文本框操作:(该系列文章js的操作内容为jQuery,jquery需要各位自己引入,后期会补充进js的操作方式)
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="utf-8"/> <title>Form表单文本框操作示例1</title> <style> body{font-size:14px;} label{display:inline-block;width:7em;margin-left:0.3em;margin-right:0.3em;}input{margin-top:0.3em;margin-bottom:0.3em;}.tipmsg{font-size:14px;color:#f00;} </style></head><body><form> <h3>input文本框</h3><hr> <div> <label>input输入框1:</label> <input type="text" name="text1" value="input文本框1"/><span class="tipmsg">input框默认type为text文本框;但如果样式库定义了type或者定义了input:not([type])则会存在样式上的区别;</span> </div> <div> <label>input输入框2:</label> <input type="text" name="text2" value="input文本框2只读" readonly="readonly"/><span class="tipmsg">input="text"含readonly="readonly"属性,内容只读,不能手动编辑;readonly="true"和readonly="false"都无法手动编辑,应该是只要有readonly属性就是只读,这两种方式都是不规范的;</span> </div> <div> <label>input输入框3:</label> <input type="text" name="text3" value="input文本框3禁用" disabled="disabled"/><span class="tipmsg">input="text"含disabled="disabled"属性,内容禁用;disabled="true"和disabled="false"都是禁用状态,应该是只要有disabled属性就是只读,这两种方式都是不规范的;disabled和readonly属性同时存在则表现为disabled的属性行为;</span> </div> <div> <label>input输入框4:</label> <input type="text" id="text4"/><span class="tipmsg">$("#text4").val("js为文本框赋值");//用js改变文本框的值(id选择器)</span> </div> <div> <label>input输入框5:</label> <input type="text" name="input5"/><span class="tipmsg">$("input[name='input5']").val("js为文本框赋值");//用js改变文本框的值(name选择器);暂不讨论name数组和class</span> </div> <div> <label>input输入框6:</label> <input type="text" id="text6" value="文本框focus切换只读属性"/><span class="tipmsg">$("#text6").attr("readonly","readonly");//js控制文本框只读$("#text6").removeAttr("readonly");//js移除readonly属性;本例中还讲到了js的css();<br>•对于HTML元素本身就带有的固有属性,在处理时,使用prop方法。<br> •对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法。<br>之前我一直用的attr,今天突然用到了控制单选按钮是否禁用时发现用attr无效,才注意到用prop;</span> </div></form><script src="./jquery-1.x.min.js"></script><script>$(function(){ $("#text4").val("js为文本框赋值"); $("input[name='input5']").val("js为文本框赋值"); $("#text6").focus(function(){ /* var read = $(this).attr("readonly");if(read==undefined){ $(this).attr("readonly","readonly"); $(this).css("background-color","#eee");}else{ $(this).removeAttr("readonly"); $(this).css("background-color","#fff");}*/var read = $(this).prop("readonly");if(read==false){//attr这里是undefined,而prop的为false; $(this).prop("readonly","readonly"); $(this).css("background-color","#eee");}else{ $(this).removeProp("readonly"); $(this).css("background-color","#fff");} }); });</script></body></html>
对于下拉、单选、复选,发现自己每次都要去网上重新找符合自己需求的方式取值或者选中,故准备写Form系列的文章备查。这篇比较基础,但希望给觉得有用的人以借鉴。
0 0
- Form表单之input文本框操作
- 表单元素form之input
- form表单input标签
- Form表单之radio单选框操作
- Form表单之复选框checkbox操作
- form表单的input对象
- form表单的input对象
- input文本框的常用操作
- jQuery操作form表单
- form表单操作
- 操作form表单
- jQuery实现文本框回车键提交form表单
- javaweb网上书店之表单提交---文本框被disabled后request.form不能得到其值
- JavaScript基础(5)之form表单-基本操作
- form表单中的input type="submit"
- form表单提交与input相关问题
- form表单中的input有哪些类型
- JSP Form表单input元素不能提交
- AndroidStudio导入项目一直卡在Building gradle project info
- redis-cluster集群搭建
- my代码跟踪之device_register
- 160. Intersection of Two Linked Lists
- State Estimation for Robotics_简介
- Form表单之input文本框操作
- [积累] gerrit 不经代码审核直接push进库的方法
- PowerDesigner利用oracle11gR2中的表逆向生成物理模型
- Mysgit+copssh+git extension+Visual studio windows7 服务器与客户端的搭建
- ubuntu添加新用户
- 学通C#网络编程——第四篇 TCP应用编程
- 论打造团队
- RecyclerView机制分析: State
- Linux 之 JDK 的安装(配置环境变量)