Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法从单独的文件访问jQuery或基础函数吗?_Javascript_Jquery_Modal Dialog_Zurb Foundation - Fatal编程技术网

Javascript 无法从单独的文件访问jQuery或基础函数吗?

Javascript 无法从单独的文件访问jQuery或基础函数吗?,javascript,jquery,modal-dialog,zurb-foundation,Javascript,Jquery,Modal Dialog,Zurb Foundation,基本上,问题在于: 我有一些代码将事件侦听器添加到页面上的每个按钮。如果未设置登录cookie,则代码使用基础提供的函数触发基础模型。如果设置了cookie并且用户已登录,则用户将被定向到所需页面 问题是,即使基础文件被包含在同一个页面中,我也不能从文件中发射基础代码;其他一切都在起作用。发生什么事?代码如下: // Anonymous function wrapper (function () { // getting an array of all buttons on the pa

基本上,问题在于: 我有一些代码将事件侦听器添加到页面上的每个按钮。如果未设置登录cookie,则代码使用基础提供的函数触发基础模型。如果设置了cookie并且用户已登录,则用户将被定向到所需页面

问题是,即使基础文件被包含在同一个页面中,我也不能从文件中发射基础代码;其他一切都在起作用。发生什么事?代码如下:

// Anonymous function wrapper
(function () {
    // getting an array of all buttons on the page, based on a button class
    var button = document.getElementsByClassName('button');

    // main function to run after ternary operator check (found at bottom)
    function run () {
        // cookieCheck() returns true/false depending on whether 
        // the cookie is set
        var cookie = cookieCheck(),
            modal = document.getElementById('loginModal'),
            i, j = button.length;

        // looping through each button, applying an even listener
        for (i = 0; i < j; ++i) {
            (function (i) {
                button[i].addEventListener('click', function (e) {
                    var link = e.target.getAttribute('target');
                    if (cookie === false) {
                        // Firing foundation function. PROBLEM IS HERE!!!
                        $('#myModal').foundation('reveal', 'open');
                    } else {
                        // if cookie is set, direct user to proper page
                        e.target.href = link;
                    }
                }, false);
            }(i));
        }
    }

    // if buttons exist on the page, the function runs.
    // this prevents errors being thrown in the console on pages with no buttons
    button ? run() : false;
}());
HTML我没有写这部分,也没有写PHP,我只是在这里写了javascript:

<?php wp_footer(); ?>

    <div id="loginModal" class="reveal-modal small" data-reveal>
        <?php gravity_form( 2, true, true, false, '', false ); ?>
    <a class="close-reveal-modal">&#215;</a></div>

    <script>
        (function($) {
            $(document).foundation();
        })(jQuery);
    </script>

    <!-- This is the script in question /-->
    <script src="/static/themes/RWv3/js/custom.js"></script>
    <?php if (is_front_page()) { ?>
        <script src="/static/themes/RWv3/js/vendor/main.js"></script>
    <?php } ?>
</body>
为什么会这样


谢谢

你能在脚本包含的地方发布HTML吗?在使用该函数的文件之前是否包含该函数的文件?@MisterDev,该文件包含在提供该函数的其他文件的下面。但是请记住这是一个疯狂的WordPress站点,我讨厌WordPress,所以也许这是一个因素。@ AWELY当然,一个SECF你添加控制台。