编程语言
首页 > 编程语言> > javascript – 我正在尝试在页面加载时自动点击一个信号按钮..但不工作

javascript – 我正在尝试在页面加载时自动点击一个信号按钮..但不工作

作者:互联网

如何在页面加载时自动点击“信号”按钮?我正在尝试使用javascript和jquery代码,但它无法正常工作.

页面加载时,第一个代码在这里

<div id="onesignal-bell-launcher" class="onesignal-bell-launcher onesignal-bell-launcher-md onesignal-bell-launcher-bottom-right onesignal-bell-launcher-theme-default onesignal-bell-launcher-active">
    <div class="onesignal-bell-launcher-button">
        <!--?xml version="1.0" encoding="utf-8"?-->
        <!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
        <svg version="1.1" class="onesignal-bell-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="99.7px" height="99.7px" viewBox="0 0 99.7 99.7" style="filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));; -webkit-filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));;" xml:space="preserve">
            <g>
                <circle class="background" cx="49.9" cy="49.9" r="49.9"></circle>
                <g id="Layer_2">
                    <g>
                        <path class="foreground" d="M50.1,66.2H27.7c0,0-2-0.2-2-2.1c0-1.9,1.7-2,1.7-2s6.7-3.2,6.7-5.5c0-2.3-1.1-3.9-1.1-13.3
                            s6-16.6,13.2-16.6c0,0,1-2.4,3.9-2.4c2.8,0,3.8,2.4,3.8,2.4c7.2,0,13.2,7.2,13.2,16.6s-1,11-1,13.3c0,2.3,6.7,5.5,6.7,5.5
                            s1.7,0.1,1.7,2c0,1.8-2.1,2.1-2.1,2.1H50.1z"></path>
                        <path class="foreground" d="M42.9,68.5h14.5c0,0-1,6.3-7.2,6.3S42.9,68.5,42.9,68.5z"></path>
                        <ellipse class="stroke" cx="49.9" cy="49.9" rx="37.4" ry="36.9"></ellipse>
                    </g>
                </g>
            </g>
        </svg>
        <div class="pulse-ring"></div>
    </div>
    <div class="onesignal-bell-launcher-badge"></div>
    <div class="onesignal-bell-launcher-message">
        <div class="onesignal-bell-launcher-message-body">Lütfen bildirimlere izin veriniz..</div>
    </div>
    <div class="onesignal-bell-launcher-dialog" style="filter: drop-shadow(0px 2px 2px rgba(34,36,38,.15));; -webkit-filter: drop-shadow(0px 2px 2px rgba(34,36,38,.15));;">
        <div class="onesignal-bell-launcher-dialog-body">
            <h1>Site bildirimlerini yönet</h1>
            <div class="divider"></div>
            <div class="push-notification">
                <div class="push-notification-icon push-notification-icon-default"></div>
                <div class="push-notification-text-container">
                    <div class="push-notification-text push-notification-text-short"></div>
                    <div class="push-notification-text"></div>
                    <div class="push-notification-text push-notification-text-medium"></div>
                    <div class="push-notification-text"></div>
                    <div class="push-notification-text push-notification-text-medium"></div>
                </div>
            </div>
            <div class="action-container">
                <button type="button" class="action" id="subscribe-button">TAKİP ET</button>
            </div>
            <div class="divider"></div>
            <div class="kickback">Powered by <a href="https://onesignal.com" class="kickback" target="_blank">OneSignal</a></div>
        </div>
    </div>
</div>

单击第一个按钮时,第二个按钮打开

<div class="action-container">
    <button type="button" class="action" id="subscribe-button">TAKİP ET</button>
</div>

解决方法:

首先,您需要注册onclick事件,其中回调函数具有添加元素所需的代码,然后触发单击事件

$( document ).ready(function() {
     $("#subscribe-button").on("click", function() {
          $(this).parent().append("<div class="action-container"><button type="button" class="action" id="subscribe-button2">TAKİP ET</button></div>")
     });
     $("#subscribe-button").trigger('click');
});

请记住,在这里你应该有不同的id到第二个按钮,No 2 HTML可以有相同的id,如果你将尝试获取元素它将只给你第一个DOM

标签:onesignal,javascript,php,jquery,wordpress
来源: https://codeday.me/bug/20190724/1525203.html