How to handle change text of span

后端 未结 3 421
清酒与你
清酒与你 2021-01-03 17:56

I\'m using jQuery and I want to show some calculation in a span (called span1) and I want when text of span1 changed do some calculation on it\'s v

3条回答
  •  無奈伤痛
    2021-01-03 18:35

    Span does not have 'change' event by default. But you can add this event manually.

    Listen to the change event of span.

    $("#span1").on('change',function(){
         //Do calculation and change value of other span2,span3 here
         $("#span2").text('calculated value');
    });
    

    And wherever you change the text in span1. Trigger the change event manually.

    $("#span1").text('test').trigger('change'); 
    

提交回复
热议问题