Javascript _ javascript tips

Source: Internet
Author: User
This article describes how to restrict the input value type of a text box in javascript. it involves javascript mouse events, keyboard buttons, and string-related operation techniques, which are of great practical value, for more information about how to restrict the input value type of a text box in javascript, see the following example. Share it with you for your reference. The specific analysis is as follows:

Requirements: only numbers and decimal places can be entered in all text boxes. Other symbols cannot be entered;

The key point is that I want to limit the number when the user inputs, instead of determining when the user submits -- that is to say, if the user enters a number or decimal point in the text box, the user can enter the number normally. if the user inputs non-numeric characters such as letters, the text box does not respond, and the entered characters are not displayed.

Script var s ="57&&event.keyCode!=190) return false\" "+ //限制只能输入数字"onblur=\"value=value.replace(/[^0-9\.]/g,'')\" " + //限制鼠标点击输入非数字"onbeforepaste=\"clipboardData.setData(\"text\"," + //限制只能粘贴数字"clipboardData.getData(\"text\").replace(/[^0-9\.]/g,''))\">";document.write(s);《script》

希望本文所述对大家的javascript程序设计有所帮助。

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.