Triggering the click event with jQuery results in the wrong value of the checkbox obtained in the callback function

The page has a checkbox, which is selected by default and binds the click event. Use event.target.checked in the event's callback function to check the latest value of the checkbox.

The user clicks the checkbox with the mouse, and in the callback function, the value of event.target.checked is false, no problem.

In Jasmine, if jQuery is used to trigger the click event, in the callback function, the value of event.target.checked is true. After the callback function is executed, the checkbox becomes unchecked.

Solution:

Use document.getElementById to get the checkbox, and then trigger the click event to get the correct value in the callback function.

 

 References:

https://bugs.jquery.com/ticket/3827#comment:9

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327091113&siteId=291194637