input类型和限制

常用限制 input的方法
1.取消按钮按下时的虚线框,在 input里添加属性值 hideFocus 或者 HideFocus=true
< input type="submit" value="提交" hidefocus="true" />

2.只读文本框内容,在 input里添加属性值 readonly
< input type="text" readonly />

3.防止退后清空的TEXT文档(可把style内容做做为类引用)
< input type="text" style="behavior.:url(#default#savehistory);" />

4.ENTER键可以让光标移到下一个输入框
< input type="text" nkeydown="if(event.keyCode==13)event.keyCode=9" />

5.只能为中文(有闪动)
< input type="text" nkeyup="value=value.replace(/[ -~]/g,'')" nkeydown="if(event.keyCode==13)event.keyCode=9" />

6.只能为数字(有闪动)
< input type="text" nkeyup="value=value.replace(/[^"d]/g,'') " nbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^"d]/g,''))" />

7.只能为数字(无闪动)
< input type="text" style="ime-mode:disabled" nkeydown="if(event.keyCode==13)event.keyCode=9" nkeypress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false" />

8.只能输入英文和数字(有闪动)
< input type="text" nkeyup="value=value.replace(/["W]/g,'')" nbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^"d]/g,''))" />

9.屏蔽输入法
< input type="text" name="url" style="ime-mode:disabled" nkeydown="if(event.keyCode==13)event.keyCode=9" />

10. 只能输入 数字,小数点,减号(-) 字符(无闪动)
< input nkeypress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false" />

11. 只能输入两位小数,三位小数(有闪动)
< input type="text" maxlength="9" nkeyup="if(value.match(/^"d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/"."d*"./g,'.')" nkeypress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^"d{3}$/) || /"."d{3}$/.test(value)) {event.returnValue=false}" />
回答者: cld007 - 助理 三级 11-24 14:48
提问者对于答案的评价:
谢谢.. 好详细额!
评价已经被关闭目前有 0 个人评价

50% (0)
不好
50% (0)
其他回答
共 2 条
http://www.w3.org/TR/REC-html32.html

HTML标准的RFC

type
Used to set the type of input field:

type=text (the default)
A single line text field whose visible size can be set using the size attribute, e.g. size=40 for a 40 character wide field. Users should be able to type more than this limit though with the text scrolling through the field to keep the input cursor in view. You can enforce an upper limit on the number of characters that can be entered with the maxlength attribute. The name attribute is used to name the field, while the value attribute can be used to initialize the text string shown in the field when the document is first loaded.

< input type=text size=40 name=user value="your name">

type=password
This is like type=text, but echoes characters using a character like * to hide the text from prying eyes when entering passwords. You can use size and maxlength attributes to control the visible and maximum length exactly as per regular text fields.

< input type=password size=12 name=pw>

type=checkbox
Used for simple Boolean attributes, or for attributes that can take multiple values at the same time. The latter is represented by several checkbox fields with the same name and a different value attribute. Each checked checkbox generates a separate name/value pair in the submitted data, even if this results in duplicate names. Use the checked attribute to initialize the checkbox to its checked state.

< input type=checkbox checked name=uscitizen value=yes>

type=radio
Used for attributes which can take a single value from a set of alternatives. Each radio button field in the group should be given the same name. Radio buttons require an explicit value attribute. Only the checked radio button in the group generates a name/value pair in the submitted data. One radio button in each group should be initially checked using the checked attribute.

< input type=radio name=age value="0-12">
< input type=radio name=age value="13-17">
< input type=radio name=age value="18-25">
< input type=radio name=age value="26-35" checked>
< input type=radio name=age value="36-">

type=submit
This defines a button that users can click to submit the form's contents to the server. The button's label is set from the value attribute. If the name attribute is given then the submit button's name/value pair will be included in the submitted data. You can include several submit buttons in the form. See type=image for graphical submit buttons.

< input type=submit value="Party on ...">

type=image
This is used for graphical submit buttons rendered by an image rather than a text string. The URL for the image is specified with the src attribute. The image alignment can be specified with the align attribute. In this respect, graphical submit buttons are treated identically to IMG elements, so you can set align to left, right, top, middle or bottom. The x and y values of the location clicked are passed to the server: In the submitted data, image fields are included as two name/value pairs. The names are derived by taking the name of the field and appending ".x" for the x value, and ".y" for the y value.

Now choose a point on the map:

<input type=image name=point src="map.gif">

Note: image fields typically cause problems for text-only and speech-based user agents!
type=reset
This defines a button that users can click to reset form. fields to their initial state when the document was first loaded. You can set the label by providing a value attribute. Reset buttons are never sent as part of the form's contents.

<input type=reset value="Start over ...">

type=file
This provides a means for users to attach a file to the form's contents. It is generally rendered by text field and an associated button which when clicked invokes a file browser to select a file name. The file name can also be entered directly in the text field. Just like type=text you can use the size attribute to set the visible width of this field in average character widths. You can set an upper limit to the length of file names using the maxlength attribute. Some user agents support the ability to restrict the kinds of files to those matching a comma separated list of MIME content types given with the ACCEPT attribute e.g. accept="image/*" restricts files to images. Further information can be found in RFC 1867.

<input type=file name=photo size=20 accept="image/*">

type=hidden
These fields should not be rendered and provide a means for servers to store state information with a form. This will be passed back to the server when the form. is submitted, using the name/value pair defined by the corresponding attributes. This is a work around for the statelessness of HTTP. Another approach is to use HTTP "Cookies".

<input type=hidden name=customerid value="c2415-345-8563">

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-462653/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12639172/viewspace-462653/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值