Home > Web Front-end > JS Tutorial > jquery implements clicking to add a number

jquery implements clicking to add a number

WBOY
Release: 2021-11-17 09:50:11
Original
4373 people have browsed it

Method: 1. Create a button button and bind the click event, specify an event processing function; 2. In the event processing function, use the "$(numeric object).val();" statement to obtain Numeric value; 3. Use the "$(numeric object).val(numeric value*1 1);" statement to add 1 to the obtained value.

jquery implements clicking to add a number

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

jquery method of adding a number by clicking

1. Create a new html file, named test.html, to explain how to use jquery implements the mouse click to add 1 to the number in the plus sign text box. Create a text box using the input tag and set its default value to 1. Set the id of the input tag to myput, which is mainly used to obtain the input object through this id below.

In the test.html file, use the button tag to create a button with the button name " " plus sign. Bind the onclick click event to the button button. When the button is clicked, the addone() function is executed.

jquery implements clicking to add a number

2. In the js tag, create the addone() function. Within the function, obtain the input object through id(myput), and use the val() method to obtain its value, then add 1 to the obtained value, and then reassign the value to the input through the val() method, thereby realizing the operation of adding 1 to the text box number.

jquery implements clicking to add a number

Open the test.html file in the browser and click the plus sign to see the effect.

jquery implements clicking to add a number

After clicking the button

jquery implements clicking to add a number

Summary:

1. Create a test.html file.

2. In the file, create a text box using the input tag, set the id of the input tag to myput, and create a button button to trigger the execution of the js function.

3. In the js tag, create a function. Within the function, obtain the input object through id(myput), use the val() method to obtain its value, and then add 1 to the obtained value. Then reassign the value to the input through the val() method, thereby realizing the operation of adding 1 to the text box number.

Notes

The res value is multiplied by 1, which is mainly used to convert strings to numeric types.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of jquery implements clicking to add a number. 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