JS controls Input

Source: Internet
Author: User
  1. 1. Converts lowercase letters to uppercase letters:
  2. <Input type = "text" name = "xianjin" class = "input02" style = "text-transform: uppercase;">
  3. Or
  4. <Input type = "text" name = "xianjin" onkeyup = "This. value = This. value. tolocaleuppercase ()">
  5. 2. Convert uppercase letters to lowercase letters automatically.
  6. <Input type = "text" name = "xianjin" class = "input02" style = "text-transform: lowercase;">
  7. Or
  8. <Input type = "text" name = "xianjin" onkeyup = "This. value = This. value. tolocalelowercase ()">
  9. 3. Prevent text files from being cleared.
  10. <Input style = behavior: URL (# default # savehistory); type = text id = opersistinput>
  11. 4. Press enter to move the cursor to the next input box.
  12. <Input onkeydown = "If (event. keycode = 13) event. keycode = 9">
  13. 5. It can only be Chinese (with flashing)
  14. <Input onkeyup = "value = value. Replace (/[-~] /G, '')" onkeydown = "If (event. keycode = 13) event. keycode = 9">
  15. 6. It can only be numbers (with flashing)
  16. <Input onkeyup = "value = value. replace (/[^ \ D]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g, '')">
  17. 7. Only numbers are allowed (no flashing)
  18. <Input style = "ime-mode: Disabled" onkeydown = "If (event. keycode = 13) event. keycode = 9 "onkeypress =" If (event. keycode <48 | event. keycode> 57) event. returnvalue = false ">
  19. Or
  20. Onkeyup = "If (isnan (value) {alert ('must be number'); value = '';}"
  21. 8. Only English and numbers can be entered (with flashing)
  22. <Input onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g, '')">
  23. 9. shielded Input Method
  24. <Input type = "text" name = "url" style = "ime-mode: Disabled" onkeydown = "If (event. keycode = 13) event. keycode = 9">
  25. 10. You can only enter numbers, decimal points, minus (-) characters (no flashing)
  26. <Input onkeypress = "If (event. keycode! = 46 & event. keycode! = 45 & (event. keycode <48 | event. keycode> 57) event. returnvalue = false ">
  27. 11. Change the font size of the input box. The font of the button remains unchanged.
  28. <Input name = "startdate" type = "text" style = "font-family: Arial; color: #008000; font-size: 27px" size = "10">
  29. 12. Up to 255 characters can be entered
  30. <Textarea name = "TXT" rows = "7" id = "TXT" onkeypress = "xz ()"> </textarea>
  31. <Script language = "JavaScript">
  32. Function xz ()
  33. {
  34. If (txt. value. length> 255)
  35. Event. keycode = 0;
  36. TXT. value = TXT. value. substr (0,255 );
  37. }
  38. </SCRIPT>
  39. Commonly used methods to limit input
  40. 1. When the cancel button is pressed, add the value hidefocus or hidefocus = true to the input.
  41. Input type = submit value = submit hidefocus = true
  42. 2. Read-only text box content, add the attribute value readonly in input
  43. Input type = text readonly
  44. 3. Prevent text files from being cleared (style content can be referenced as a class)
  45. Input type = text style = behaviorurl (# default # savehistory );
  46. 4. Press enter to move the cursor to the next input box.
  47. Input type = text onkeydown = If (event. keycode = 13) event. keycode = 9
  48. 5. It can only be Chinese (with flashing)
  49. Input type = text onkeyup = value. Replace ([-~] G, '') onkeydown = If (event. keycode = 13) event. keycode = 9
  50. 6. Only numbers are allowed (with flashing)
  51. Input type = text onkeyup = value. replace ([^ d] G, '') onbeforepaste = clipboardData. setdata ('text', clipboardData. getdata ('text '). replace ([^ d] G ,''))
  52. 7. Only numbers are allowed (no flashing)
  53. Input type = text style = ime-modedisabled onkeydown = If (event. keycode = 13) event. keycode = 9 onkeypress = If (event. keycode48 event. keycode57) event. returnvalue = false
  54. 8. Only English and numbers can be entered (with flashing)
  55. Input type = text onkeyup = value. replace ([w] G, '') onbeforepaste = clipboardData. setdata ('text', clipboardData. getdata ('text '). replace ([^ d] G ,''))
  56. 9. shielded Input Method
  57. Input type = text name = URL style = ime-modedisabled onkeydown = If (event. keycode = 13) event. keycode = 9
  58. 10. You can only enter numbers, decimal points, minus (-) characters (no flashing)
  59. Input onkeypress = If (event. keycode! = 46 & event. keycode! = 45 & (event. keycode48 event. keycode57) event. returnvalue = false
  60. 11. Only two decimal places can be entered, and three decimal places (with flashing)
  61. Input type = text maxlength = 9 onkeyup = If (value. match (^ d {3} $) value = value. replace (value, parseint (value10); value = value. replace (. d. G ,'. ') onkeypress = If (event. keycode48 event. keycode57) & event. keycode! = 46 & event. keycode! = 45 value. Match (^ d {3} $). d {3} $. Test (value) {event. returnvalue = false}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.