Javascript event that fires without user interaction?

后端 未结 7 1347
离开以前
离开以前 2021-01-22 06:59

A textbox on my form may change depending on what\'s selected in various drop down lists.

Is there a way to call a javascript function when the textbox value changes? <

相关标签:
7条回答
  • 2021-01-22 07:35

    No, javascript-triggered changes to form elements don't trigger events. If they did, this would cause all sorts of recursive infinite loops.

    The simple solution is to call your onchange function manually whenever you change the value of the textbox, however you could also use some kind of wrapper function. As a very basic example:

    function updateTextField(new_text) {
      text_field.value = new_text;
      text_field.onchange();
    }
    
    0 讨论(0)
提交回复
热议问题