移动到插件后显示模态的按钮没有做任何事情

Button to display modal is not doing anything after moving to plugin

自行解决:

只需要将文档就绪功能添加到我的脚本中。

最初我使用的是相同的代码,但在我的主题中使用:

add_action('wp_footer', function () {
    wp_enqueue_script('modal', get_stylesheet_directory_uri() . '/modal.js', array(), '1.0', false);
});

一切正常。

今天早上我决定将脚本移到我的插件中,但现在按钮什么也没做。

我在控制台中没有得到任何帮助我调试的东西。

脚本已在插件中注册并入队:

wp_register_script( 'modal_script', plugin_dir_url( __FILE__ ) . 'js/modal.js', array('jquery'), '1.0', true );
wp_enqueue_script( 'modal_script' );

按钮和类:

<button onclick="anotherFunction()" class="trigger">Request Stamp</button>
<div class="modal">
    <div class="modal-content">
        <span class="close-button">x</span>

modal.js:

var modal = document.querySelector(".modal");
var trigger = document.querySelector(".trigger");
var closeButton = document.querySelector(".close-button");

function toggleModal() {
    modal.classList.toggle("show-modal");
}

function windowOnClick(event) {
    if (event.target === modal) {
        toggleModal();
    }
}

trigger.addEventListener("click", toggleModal);
closeButton.addEventListener("click", toggleModal);
window.addEventListener("click", windowOnClick);

单击按钮帮助我调试后控制台中没有任何内容,网络显示脚本是从新插件位置加载的。

有什么想法吗?

刚刚添加:

jQuery(document).ready(function(){

我的 js 一切正常。