[英]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.
我想通过我自己的 jQuery 代码触发任何事件处理程序。 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?) (此外,Chrome DevTools 中是否有办法查看元素附加了哪些事件?)
This will make the click function work, with a id on the element.这将使点击功能工作,在元素上有一个 id。 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/尝试查看 -> https://jquerymodal.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.