我购买的HTML主题的基于JQuery的代码是指带有简写的JQuery
对象,即$
。JQuery兼容性和WordPress
但是,WordPress使用Jquery
对象作为JQuery
- 出于兼容性原因。
我想坚持WordPress的做法,并改变主题的代码与WordPress兼容。
有没有办法将该主题的JavaScript代码与JQuery对象一起使用? 为了更具体一些,我会给你一个例子;
考虑下面的JavaScript代码使用一些JQuery的魔法
/* __________________ Equal Heights __________________*/
$.fn.eqHeights=function(a){var f={child:false};var a=$.extend(f,a);var d=$(this);if(d.length>0&&!d.data("eqHeights")){$(window).bind("resize.eqHeights",function(){d.eqHeights()});d.data("eqHeights",true)}if(a.child&&a.child.length>0){var c=$(a.child,this)}else{var c=$(this).children()}var g=0;var b=0;var e=[];c.height("auto").each(function(){var h=this.offsetTop;if(g>0&&g!=h){$(e).height(b);b=$(this).height();e=[]}b=Math.max(b,$(this).height());g=this.offsetTop;e.push(this)});$(e).height(b)};
也可以考虑以下的init以该节放在这需要的Equal Height Columns
照顾。
/* ________ equal heights __________________*/
$(document).ready(function() {
$('.equalHeights').eqHeights();
});
现在......我该怎么做才能让上面的代码与WordPress兼容?
我知道我要插入一些关键的地方(一个或多个)的JQuery
串以上的地方,但不知道究竟在何处..
该手抄本网页(下面的链接)是一个很好的资源,但是,我仍然不能弄清楚是如何完成的。
http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers
实际代码为http://bombdiggitydesign.com/crisp-2/Crisp-warm/hero-equal-height-columns.html是这里http://bombdiggitydesign.com/crisp-2/Crisp-warm/assets/js/custom.js(只搜索EqualHeights)。
我刚刚复制了上面的一小段文字,以表达我的观点,而不是让你处理她巨大的custom.js。我认为我抓住的部分足以理解这是如何完成的。如果你想“$”总访问“jQuery的”,而无需在代码的其余部分更换
谢谢你的回答。我仍然得到一个'Uncaught TypeError:无法读取chrome开发人员工具中未定义错误的属性'fn'。安慰。错误在这一行。 '/ * __________________平等的高度__________________ */ $ .fn.eqHeights = function(a){var f = {c ....' –
could this http://stackoverflow.com/questions/10807430/jquery-uncaught- typeerror-can not-read-property-fn-unde-undefined-anonymous-fun是一种补救措施,以避免我收到的错误? - 如果是这样的话,这个包装会去哪里? –
我提供的链接有解决方案。我会回答我自己的问题。感谢您的帮助。 –