Implementation Method of Multiple input summation in jQuery, multiple input summation in jquery
This example describes how to implement multiple input summation of jQuery. Share it with you for your reference. The specific implementation method is as follows:
The html page code is as follows:
<Td> <input name = "add" id = "add" readonly = "readonly"/> </td> <pre name = "code" class = "html"> <td> <input name = "add1" id = "add1"/> </td> <input name = "add2" id = "add2"/> </td>
Some jQuery code is as follows:
<Script> $ ("input [id ^ = 'add']"). change (function () {var sum = 0; $ ("input [id ^ = 'add']"). each (function () {var r =/^ -? \ D + $/; // positive integer if ($ (this). val ()! = ''&&! R. test ($ (this ). val () {$ (this ). val (""); // The regular expression is not null} else if ($ (this ). val ()! = '') {Sum + = parseInt ($ (this ). val ();} document. getElementById ("add "). value = sum ;}); </script>
Because the input attribute is readonly, when you press Backspace in the browser to delete the input value, the page will return a response. For solutions, refer to the previous article JQuery implementation of methods to prevent return of the return Space key.
I hope this article will help you with jQuery programming.