我的Wordpress网站上的所有jQuery脚本都无法正常工作
None of the jQuery scripts on my Wordpress site are working
我有一个使用修改主题和许多插件的网站。我对js的了解一点也不好,所以如果以前出现过这种情况,请接受我的歉意。http://www.georgvoros.com/
似乎没有一个js正在运行,包括滑块,导航下拉列表和灯箱脚本。我已经将Wordpress更新到3.61,jQuery更新到1.10.2。
我在Chrome检查元素窗口中收到以下错误。
Uncaught TypeError: Cannot read property 'msie' of undefined jquery.tools.min.js?ver=1.2.7:13
Uncaught TypeError: Cannot set property 'touchstart' of undefined jquery.mobile.customized.min.js:10
Uncaught TypeError: Object function (b,c,d){var e=b.split(".")[0],f;b=b.split(".")[1];f=e+"-"+b;if(!d){d=c;c=a.Widget}a.expr[":"][f]=function(c){return!!a.data(c,b)};a[e]=a[e]||{};a[e][b]=function(a,b){if(arguments.length){this._createWidget(a,b)}};var g=new c;g.options=a.extend(true,{},g.options);a[e][b].prototype=a.extend(true,g,{namespace:e,widgetName:b,widgetEventPrefix:a[e][b].prototype.widgetEventPrefix||b,widgetBaseClass:f},d);a.widget.bridge(b,a[e][b])} has no method 'extend' jquery-ui.js?ver=3.6.1:539
我已经阅读了有关"$"变量导致问题的信息,但我不明白我需要在哪里更改内容。
在头部.php如下
<script type="text/javascript">
// initialise plugins
jQuery(function(){
// main navigation init
jQuery('ul.sf-menu').superfish({
delay: <?php echo of_get_option('sf_delay'); ?>, // one second delay on mouseout
animation: {opacity:'<?php echo of_get_option('sf_f_animation'); ?>'<?php if (of_get_option('sf_sl_animation')=='show') { ?>,height:'<?php echo of_get_option('sf_sl_animation'); ?>'<?php } ?>}, // fade-in and slide-down animation
speed: '<?php echo of_get_option('sf_speed'); ?>', // faster animation speed
autoArrows: <?php echo of_get_option('sf_arrows'); ?>, // generation of arrow mark-up (for submenu)
dropShadows: false
});
// prettyphoto init
jQuery("a[rel^='prettyPhoto']").prettyPhoto({
animation_speed:'normal',
slideshow:5000,
autoplay_slideshow: false,
overlay_gallery: true
});
// Initialize the gallery
jQuery("#gallery .touch-item").touchTouch();
});
</script>
<script type="text/javascript">
// Init for audiojs
audiojs.events.ready(function() {
var as = audiojs.createAll();
});
// Init for si.files
SI.Files.stylizeAll();
$(function(){
$('.sf-menu > li').append('<span class="bg-menu"></span>');
$('.sf-menu > li:last').addClass('last');
$('.recent-posts.services li:nth-child(3n)').addClass('nomargin');
if ($.browser.msie && $.browser.version < 10) {
jQuery('input[type="submit"], input[type="reset"]').hover(function(){
jQuery(this).addClass('submit-hover')
},
function(){
jQuery(this).removeClass('submit-hover')
});
}
});
jQuery(function() {
$('.right-content-area #widget_search.box h3').each(function(index) {
//get the first word
var firstWord = $(this).text().split(' ')[0];
//wrap it with span
var replaceWord = "<span>" + firstWord + "</span>";
//create new string with span included
var newString = $(this).html().replace(firstWord, replaceWord);
//apply to the divs
$(this).html(newString);
});
});
</script>
在主题脚本中.php是:
<?php
/* Register and load javascript
/*-----------------------------------------------------------------------------------*/
function my_script() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', get_bloginfo('template_url').'/js/jquery-1.10.2.min.js', false, '1.10.2');
wp_enqueue_script('jquery');
wp_enqueue_script('modernizr', get_bloginfo('template_url').'/js/modernizr.js', array('jquery'), '2.6.2');
wp_enqueue_script('superfish', get_bloginfo('template_url').'/js/superfish.js', array('jquery'), '1.7.4');
wp_enqueue_script('easing', get_bloginfo('template_url').'/js/jquery.easing.1.3.js', array('jquery'), '1.3');
wp_enqueue_script('prettyPhoto', get_bloginfo('template_url').'/js/jquery.prettyPhoto.js', array('jquery'), '3.1.5');
wp_enqueue_script('tools', get_bloginfo('template_url').'/js/jquery.tools.min.js', array('jquery'), '1.2.7');
wp_enqueue_script('mobilemenu', get_bloginfo('template_url').'/js/jquery.mobilemenu.js', array('jquery'), '1.1');
wp_enqueue_script('loader', get_bloginfo('template_url').'/js/jquery.loader.js', array('jquery'), '1.0');
wp_enqueue_script('swfobject', get_bloginfo('url').'/wp-includes/js/swfobject.js', array('jquery'), '2.3');
wp_enqueue_script('twitter', get_bloginfo('template_url').'/js/jquery.twitter.js', array('jquery'), '1.0');
wp_enqueue_script('flickr', get_bloginfo('template_url').'/js/jquery.flickrush.js', array('jquery'), '1.0');
wp_enqueue_script('touch', get_bloginfo('template_url').'/js/touchTouch.jquery.js', array('jquery'), '1.0');
wp_enqueue_script('si_files', get_bloginfo('template_url').'/js/si.files.js', array('jquery'), '1.0');
wp_enqueue_script('audiojs', get_bloginfo('template_url').'/js/audiojs/audio.js', array('jquery'), '1.0');
wp_enqueue_script('custom', get_bloginfo('template_url').'/js/custom.js', array('jquery'), '1.0');
wp_enqueue_script('camera', get_bloginfo('template_url').'/js/camera.js', array('jquery'), '1.3.3');
}
}
add_action('init', 'my_script');
/* Register and load admin javascript
/*-----------------------------------------------------------------------------------*/
function tz_admin_js($hook) {
if ($hook == 'post.php' || $hook == 'post-new.php') {
wp_register_script('tz-admin', get_template_directory_uri() . '/js/jquery.custom.admin.js', 'jquery');
wp_enqueue_script('tz-admin');
}
}
add_action('admin_enqueue_scripts','tz_admin_js',10,1);
?>
我也看不到该网站正在加载多个版本的 jQuery。
看起来你的网站依赖于很多旧的jQuery(例如jQuery Tools现在不是很常用,并且由于维护更多的jQuery UI的流行,已经有好几年了(。 更新到最新版本的jQuery可能只是破坏了大多数过时的脚本。
您可以通过简单地包含jQuery Migrate 官方插件来修复它,该插件为以前版本中的旧 jQuery 功能增加了向后兼容性,这些功能已被弃用或删除。
只需在 jQuery wp_enqueue_script()
调用后立即将其包含在wp_enqueue_script()
中,并且运气好的话可以解决许多(如果不是全部(问题。
如果这不能解决问题,则需要逐个解决问题,并使用更现代的技术重新实现它们或更新其各自的脚本依赖项。
这些错误是由您的 jQuery 版本中缺少的某些函数引起的......
jQuery.browser
(或$.browser
(在jQuery的1.9版本被删除。您站点中的某些代码似乎是为旧版本的jQuery编写的。
你可以降级到早期版本,或者更新你网站上的Javascript以使用jQuery 1.10.2。
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- ajaxToolkit PopupControlExtender不工作.过时的
- HTML标记在脚本标记中工作
- javascript扫雷器floodfill算法不能正常工作