Jquery - change event firing on page load

后端 未结 2 751
失恋的感觉
失恋的感觉 2020-12-10 20:58

I have select controls on a HTML page and using Jquery to set change event.

But the event fires on the page load and does not fire when I try to change values in the

2条回答
  •  一向
    一向 (楼主)
    2020-12-10 21:25

    Your syntax is wrong.

    By writing change(CalculateHours($(this)), you are calling the CalculateHours function and passing its return value to jQuery's change method as if it were a function. You would only write this if your function returned another function and you wanted to affffd the returned function as an event handler.

    You need to write .change(function() { CalculateHours($(this)); })

提交回复
热议问题