简体   繁体   English

页面完全加载后触发单击复选框

[英]Trigger click Checkbox After page fully loaded

How I run trigger click after page FULLY loaded我如何在页面完全加载后运行触发点击

I have a checkbox and want to trigger a click.我有一个复选框,想触发一次点击。

my code is simple我的代码很简单

jQuery(document).ready(function(){
     jQuery('.wcpf-input-checkbox[value="hoodie"]').trigger('click');
});

but it does not work, I tes the script in console after fullu loaded, my script work但它不起作用,我在 fullu 加载后在控制台中测试脚本,我的脚本工作

I also to try to check if the checkbox ready.我还尝试检查复选框是否准备就绪。 it does not work.这是行不通的。

jQuery(document).ready(function(){

jQuery('.wcpf-input-checkbox[value="hoodie"]').ready(function(){
    jQuery(this).click();
});

});

How do I trigger click to work?如何触发点击工作?

If you attach click action with this method:如果您使用此方法附加单击操作:

$(yourobj).on("click",function() {...}); $(yourobj).on("click",function() {...});

then you can change it to:那么您可以将其更改为:

$(document).on("click", 'yourobj', function(event) {...}); $(document).on("click", 'yourobj', function(event) {...});

But I don't know, you haven't posted all of your code.但我不知道,您还没有发布所有代码。

The issue for me trigger clicks only can be run after the page fully loaded so I bind my code after window load() and set timeout我的问题触发点击只能在页面完全加载后运行,所以我在窗口加载()后绑定我的代码并设置超时

Here I solved it在这里我解决了

jQuery(window).on('load', function() {
     
        setTimeout(function(){
        //your code here
            console.log('All assets are loaded');
            jQuery('.wcpf-input-checkbox[value="hoodie"]').trigger('click');
            jQuery('.wcpf-button-action-filter').trigger('click');
        }, 1000);
    })

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

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