简体   繁体   English

click()事件完成后有没有办法识别和执行代码?

[英]Is there a way to recognise and execute code after a click() event has finished?

I am programmatically clicking a button, which when done, will show a dialogue on the page. 我以编程方式单击一个按钮,完成后将在页面上显示对话框。

I want to modify the dialogue after it has been fully loaded, because part of the code following the click modifies the dialogue. 我想在完全加载后修改对话框,因为点击后的部分代码会修改对话框。

This is achievable with function with timeout, but I am exploring a way that would not use a set timeout, but rather monitor when that click action is complete. 这可以通过超时函数实现,但我正在探索一种不使用设置超时的方法,而是监视单击操作何时完成。

Note: 1. I cannot modify the code which is executed on button click. 注意:1。我无法修改按钮点击时执行的代码。 2. I need to achieve a solution which is not time based, as this could vary, although not much, is still something i would want to avoid. 2.我需要实现一个不基于时间的解决方案,因为这可能会有所不同,尽管不是很多,但我仍然希望避免这种情况。

Sample code below tha works - enough time is allowed for click to finish 下面的示例代码可以工作 - 足够的时间允许点击完成

function modifyDialogue() {
    $("#dialogue").click();
    setTimeout(function() { 
        $("#scrollBar").remove();
    }, 30);
}

Sample code that doesnt work - not enought time for scrollBar to be rendered. 不起作用的示例代码 - 没有时间来渲染scrollBar。 ScrollBar renders based on the length of text inside dialogue. ScrollBar根据对话内的文本长度进行渲染。 But since time is not enough, the removal does not happen. 但由于时间不够,不会发生移除。

function modifyDialogue() {
    $("#dialogue").click();
    $("#scrollBar").remove();
}

Edited: This no matter when it loads will hide the scroll bar. 编辑:这无论何时加载都会隐藏滚动条。

function modifyDialogue() {
    $("#dialogue").click();
    $("body").css("overflow", "hidden");
}
// Alternate
$( "button" ).on( "click", function() {
  $("body").css("overflow", "hidden");
});

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

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