简体   繁体   English

将click事件绑定到Javascript函数

[英]Bind click event to Javascript function

I have Jquery latest connected and working with other parts of application. 我有最新的Jquery连接,并与应用程序的其他部分一起工作。

0. End goal: for a modal window to appear on the screen. 0.最终目标:使模态窗口出现在屏幕上。

1. I click on a button. 1.我单击一个按钮。

2. A function runs that append a modal to body 2.运行将模式附加到body函数

3. With modals, in order for this modal to actually show on the screen, I need to press a button that has data-target="#EnterModalNameHere" 3.使用模态时,为了使该模态实际显示在屏幕上,我需要按下一个按钮,该按钮的data-target="#EnterModalNameHere"

4. I make a hidden button in index.html that has the needed data-target property. 4.我在index.html中创建一个具有所需data-target属性的隐藏按钮。

5. I would like to be able to click this hidden button once the function in step 2 finishes appending the modal. 5.我希望能够在步骤2中的功能完成附加模态后单击该隐藏按钮。

How can I tell Javascript "once finished appending modal, click on hidden button"? 我怎样才能告诉Javascript“附加模态后,单击隐藏按钮”?

You can create an Event. 您可以创建一个事件。

You can create a custom Event which would be dispatch (trigger) immediately after the document is ready. 您可以创建一个自定义事件,该事件将在文档准备好后立即分派(触发)。 So, in your situation, since you aren't using a media query, you can use : 因此,根据您的情况,由于您没有使用媒体查询,因此可以使用:

  • SetTimeout like setTimeout(() => { do something }, timeout); SetTimeout类似于setTimeout(() => { do something }, timeout); . So, the timeout could be 1000 - which means 1sec and so on, 因此,超时时间可能是1000-表示1秒,依此类推,
  • A custom event which you can trigger when the modal successfully appended to the body. 一个自定义事件,您可以在模态成功附加到主体时触发。
  • An Event Listeners Like load window.onload = function() { enter code here } 像load window.onload = function() { enter code here }的事件监听器window.onload = function() { enter code here }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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