简体   繁体   English

将jQuery与WordPress主题一起使用时出错

[英]Error when using jQuery with WordPress theme

I purchased a WordPress theme and have begun customizing it. 我购买了WordPress主题,并已开始对其进行自定义。 There is one aspect of the theme that I cannot for the life of me figure out why it is redirecting to a page called "undefined". 在我的一生中,该主题的一个方面我无法弄清楚为什么它重定向到名为“ undefined”的页面。

sdndaily.com is the site in question. sdndaily.com是有问题的网站。

!function (a, b) {
'object' == typeof module && 'object' == typeof module.exports ? module.exports = a.document ? b(a, !0)  : function (a) {
    if (!a.document) throw new Error('jQuery requires a window with a document');
    return b(a)
}
 : b(a)
}('undefined' != typeof window ? window : this, function (a, b) {
var c = [
],
d = c.slice,
e = c.concat,
f = c.push,
g = c.indexOf,
h = {
},
i = h.toString,
j = h.hasOwnProperty,
k = {
},
l = '1.11.1',
m = function (a, b) {
    return new m.fn.init(a, b)
}

In the top right corner there is an envelope icon that uses JavaScript to drop down a section to insert your e-mail. 右上角有一个信封图标,该信封图标使用JavaScript下拉部分以插入您的电子邮件。 Shortly after clicking it, you are redirected to a page titled "undefined" and firebug spits an error: 单击它后不久,您将被重定向到标题为“ undefined”的页面,萤火虫吐出一个错误:

Error( "jQuery requires a window with a document" );

Easiest solution is to turn the a tag below into a span. 最简单的解决方案是将下面的标签变成跨度。 I tested this on your site and it works like a charm: 我在您的网站上对此进行了测试,它的工作原理很吸引人:

<div id="collapse-trigger">
    <a data-toggle="collapse" class="collapse collapsed" data-target="#newsletter">
    <i class="icon-envelope-alt"></i>   </a>
</div>

Becomes: 成为:

<div id="collapse-trigger">
    <span data-toggle="collapse" class="collapse collapsed" data-target="#newsletter">
    <i class="icon-envelope-alt"></i>   </span>
</div>

Alternatively, find the action handler JS functions and add the event parameter and event.preventDefault(); 或者,找到动作处理程序JS函数,并添加事件参数和event.preventDefault();。 on top of the function: 在功能之上:

$('your_selector').click(function(event) {
    event.preventDefault();

    ...
})

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

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