简体   繁体   English

自动点击按钮(在 Wordpress 中)

[英]Auto click on button (In Wordpress)

In this code:在这段代码中:

<div id="tagsdiv-post_tag" class="postbox " >
<div class="inside">

<div class="tagsdiv" id="post_tag">
    <div class="jaxtag">
        <div class="ajaxtag hide-if-no-js">
        <p><input type="text" id="new-tag-post_tag" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
        <input type="button" class="button tagadd" value="Add" tabindex="3" /></p>
    </div>
        </div>


</div>
</div>
</div>

I want auto click on this button:我想自动点击这个按钮:

<input type="button" class="button tagadd" value="Add" tabindex="3" />

I tried with this code:我试过这段代码:

$(".ajaxtag input.button").click(); 

but it's not working.但它不起作用。 Thats code get from Wordpress admin post page.那是从 Wordpress 管理帖子页面获取的代码。

Try attaching an ID to the button, using jQuery to search the button by id, and click it... Only when the entire site is loaded.尝试在按钮上附加一个 ID,使用 jQuery 按 id 搜索按钮,然后单击它...仅当整个站点加载时。 Example below.下面的例子。

$(document).ready(function() {
     document.getElementById('ButtonId').click(); 
});

where 'ButtonId' is the ID of the button you want to click其中 'ButtonId' 是您要单击的按钮的 ID

Try attaching something to your button though, its not doing anything for now.尝试在您的按钮上附加一些东西,它现在什么都不做。

$(".ajaxtag input.button").trigger('click');

try this.尝试这个。

It appears to me that your code does work - see this fiddle as an example.在我看来,您的代码确实有效 - 以这个小提琴为例。 Note that you need to put this code in the onload event, using $(document).ready() .请注意,您需要使用$(document).ready()将此代码放入 onload 事件中。

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

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