简体   繁体   中英

How to trigger an event in jQuery?

I'm working on a page that opens a modal window when the user clicks a certain radio button. I want to trigger whatever that event handler is via my own jQuery code. Right now, I'm attempting to mimic a user clicking on the radio button by:

$("#myRadioButton").trigger("click");

The code works somewhat. The state of the radio button does become selected. However, the modal window does not open.

What must I do to trigger the events and event handlers that make the modal window open?

(Also, is there a way in Chrome DevTools to see what events are attached to an element?)

This will make the click function work, with a id on the element. You will need to make some logic for the modal itself, inside the function.

Not sure there is a way to see the events in the developer console.

 $( "#myRadioButton" ).click(function() {
    
    //Whatever you wants to happen, when you click the button
     alert( "You clicked on #myRadioButton" );
    });

Try and check out -> https://jquerymodal.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM