Home > Web Front-end > JS Tutorial > How to convert numbers with jquery

How to convert numbers with jquery

藏色散人
Release: 2020-11-30 14:52:22
Original
3635 people have browsed it

Jquery method of converting strings into numbers: First use the script tag to introduce the jquery.min.js file into the current page; then use the input tag to create a text box; then use the button tag to create a button; and finally use The parseInt method converts a string into a number.

How to convert numbers with jquery

The operating environment of this tutorial: windows10 system, jquery2.2.4, this article is applicable to all brands of computers.

Recommended: "jquery video tutorial"

Create a new html file, named test.html, to explain how jquery converts strings into numbers.

How to convert numbers with jquery

In the test.html file, use the script tag to introduce the jquery.min.js file into the current page. Only after successfully loading the file can you use the jquery method.

How to convert numbers with jquery

In the test.html file, use the input tag to create a text box for inputting strings, and set the id of the input tag to num, which is mainly used for the following The id gets the input object.

How to convert numbers with jquery

In the test.html file, create a button using the button tag and set its id to mybutton.

How to convert numbers with jquery

In the test.html file, use $ to get the button object by id, bind the click event to it, and when the button is clicked, execute the function method.

How to convert numbers with jquery

In the function method, obtain the input object through the id (num) of the input, use the val() method to obtain the input string, and use the parseInt() method or parseFloat( ) method converts a string into a number. Finally, use the alert() method to output the results. Note: The parseInt() method returns an integer, while the parseFloat() method returns a floating point number.

How to convert numbers with jquery

Open the test.html file in the browser, enter the characters, click the button to view the results.

How to convert numbers with jquery

The above is the detailed content of How to convert numbers with jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template