简体   繁体   English

使用JQuery或Javascript单击网页上的按钮

[英]Clicking a button on a webpage using JQuery or Javascript

I've been rummaging through the web to how to click buttons for a project I'm working on with Javascript+JQuery(Still not very good). 我一直在网上浏览如何在我正在使用Javascript + JQuery处理的项目中单击按钮(仍然不太好)。 Luckily I was able to find my answer and figured out how to click basic HTML buttons that looked like this(Cut off some of the code just to get the point across). 幸运的是,我能够找到答案,并且弄清楚了如何单击看起来像这样的基本HTML按钮(删除一些代码只是为了理解这一点)。

<div class="ui-block-a">
    <input type="submit" value="Buy Now" data-theme="d">
</div> 

But now I've come across a button like this. 但是现在我遇到了这样的按钮。

<div id="BuyWithRobux">
    <div data-expected-currency="1" data-asset-type="T-Shirt" class="btn-primary btn-medium PurchaseButton " data-se="item-buyforrobux" data-item-name="Donations" data-item-id="170938328" data-expected-price="2" data-product-id="20832770" data-expected-seller-id="180359" data-bc-requirement="0" data-seller-name="Clone3102">
        Buy with R$
        <span class="btn-text">Buy with R$</span>
    </div>
</div>

Just based off of what I know I don't think I can use what I used to click the last button which was... 仅基于我所知道的内容,我认为我无法使用过去单击过的最后一个按钮的功能...

 $("input[type='submit']").click();

So my question is how can I click this "button"? 所以我的问题是如何单击此“按钮”? I've tried using my old code on it to no avail. 我尝试对它使用旧代码无济于事。 I rather not use Selenium, or anything if at all possible. 我宁愿不使用Selenium,也不要使用任何可能的方法。 Could anyone help me out with this? 有人可以帮我吗? If you need anymore information just say what and I'll do my best to provide it, fairly new to this so don't know what to include sadly. 如果您还需要其他信息,请说出什么,我会尽力提供,这是很新的内容,所以不知道可悲地包括什么。

Thank you in advance. 先感谢您。

By "clicking this button" If you meant to trigger a click on div#BuyWithRobux , You can do so like 通过“单击此按钮”,如果您想触发对div#BuyWithRobux的点击,您可以这样做

$("#BuyWithRobux").click();

or 要么

$("#BuyWithRobux").trigger("click");

The syntax for triggering a click remains the same, all you've to do is to use the right selector to target the element on which you need to trigger the event. 触发点击的语法保持不变,您所要做的就是使用右选择器来定位需要触发事件的元素。

You can learn more about jQuery selectors here 您可以在此处了解有关jQuery选择器的更多信息

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

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