WordPress jQuery脚本不是在具有jQuery.noConflict用法的一个实例上启动 [英] Wordpress jQuery script is not starting on one instance with jQuery.noConflict usage

查看:74
本文介绍了WordPress jQuery脚本不是在具有jQuery.noConflict用法的一个实例上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Wordpress 2实例:本地和远程(远程应该非常相似,它主要是从本地上传的,除了一些插件).代码使用的是jQuery.noConflict方法,因为没有它,添加大量插件后就无法在本地运行.现在,当它上传到远程Wordpress时,它仍然没有从那里开始,但是它可以在本地运行:). JS方法只是没有启动.确保在HTML文件的HEAD部分中以正确的路径附加了文件.控制台中没有显示错误.

I have Wordpress 2 instances: local and remote (remote should be very similar, it was mainly uploaded from local except from a few plugins). Code is using jQuery.noConflict method, because without it it was not working locally after adding a lot of plugins. Now when it's uploaded to remote Wordpress, it's still not starting there, but it works locally :). JS method is just not started. For sure file is attached with proper path in HEAD section of HTML file. No errors displayed in console.

预期的行为是:应该显示JS警报,但没有出现.

JS代码在这里:

var jQueryAlias = jQuery.noConflict();       

function customizeWebUIForEmailSubscriberPlugin() {
        alert("customizeWebUIForEmailSubscriberPlugin"); 
        //format input button
        jQueryAlias('#elp_txt_email').removeClass('elp_textbox_class').addClass('form-control').addClass('full-width');

        //format input button
        jQueryAlias('#elp_txt_email').removeClass('elp_textbox_class').addClass('form-control').addClass('full-width');

        //format message text
        //jQuery('.elp_msg').removeClass('elp_msg').addClass('post-body');
        jQueryAlias('#elp_msg').addClass('message-format');


        //hide submit button
        jQueryAlias('#elp_txt_button').addClass('hide');        

        //hide email label
        jQueryAlias('.elp_lablebox').addClass('hide');        
    }

    jQueryAlias(customizeWebUIForEmailSubscriberPlugin);

推荐答案

问题是在两个服务器(本地和远程)上,jQuery lib都以不同顺序附加在HEAD标记中.在我的本地计算机上:jQuery附加在script.js之后,并且可以正常工作.对于远程:在我的script.js之后附加了jQuery.我不确定为什么它可以在我的远程计算机上以这种方式工作.

The problem is that on both servers (local and remote) jQuery lib is attached in HEAD tag in different sequence. On my local machine: jQuery was attached after script.js and that worked. For remote: jQuery was attached after my script.js. I am not sure why it works in such way on my remote machine.

解决方案: 添加代码后

<?php wp_enqueue_script("jquery"); ?>

就在HEAD标记之后,它可以正常工作:).

right after HEAD tag, it works:).

这篇关于WordPress jQuery脚本不是在具有jQuery.noConflict用法的一个实例上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆