<span> <span> <input type="text" id="J_month" name="share_months" class="form-90" V - on: input = "calMonths ()" > months & have spent &nbsp; <span> monthly <span id="J_share">0.00</span> yuan </span>Copy the code

The business scenario is that the allocated amount will be calculated automatically in real time after the number of months is entered in the allocation input box by clicking the mouse. The event triggered by JS is onInput or onpropertychange. For the native JS writing method, onInput is the standard event of HTML5. It is useful for detecting changes in the content of textarea, input:text, input:password, and input: Search through the user interface

JS part calculateMonths:function(){var payer = $('#J_payer').val(); var deduct = $('#J_deduct').val(); var month = $('#J_month').val(); if (payer == 3) { var amount = $('#J_company').val(); if (deduct == 1) { var pre_amount = Math.round(amount / month); $('#J_share').text(pre_amount); } else {$(' # J_share). The text (0.00); } } if (! The month) {$(' # J_share). The text (0.00); }},Copy the code