Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add a number to a click in jquery

Shulou Source: shulou.com Published: 2022-06-02 14:36:36 09月16日 Update

This article is about how jquery can click and add a number. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Method: 1, create a button button and bind the click click event, specify an event handler function; 2, in the event handler function, use the "$(digital object). Val ();" statement to get the value; 3, use the "$(digital object). Val (numeric value * 1q1);" statement to add 1 to the obtained value.

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

The method of adding a number to a click in jquery

1, create a new html file, named test.html, used to explain how to use jquery to achieve mouse click plus sign text box number plus 1. 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.

Within the test.html file, use the button tag to create a button with the name "+" plus sign. Bind the onclick click event to the button button, and execute the addone () function when the button is clicked.

2, in the js tag, create the addone () function, within the function, get the input object through id (myput), use the val () method to obtain its value, then add 1 to the obtained value, and then re-assign the value to input through the val () method, so as to realize the operation of adding 1 to the number in the text box.

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

After clicking the button

Summary:

1. Create a test.html file.

2. In the file, use the input tag to create a text box, 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, get the input object through id (myput), use the val () method to obtain its value, then add 1 to the obtained value, and then re-assign the value to input through the val () method, so as to realize the operation of adding 1 to the number in the text box.

Matters needing attention

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

Thank you for reading! This is the end of the article on "how to click and add a number in jquery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Numbers functions buttons labels methods objects files text events plus signs content numeric values more articles statements processing good practical events at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Linux Shulou Tech Info MariaDB