【问题标题】:Uncaught TypeError: $ is not a function Is anybody know what is wrong? [duplicate]未捕获的 TypeError: $ is not a function 有人知道出了什么问题吗? [复制]
【发布时间】:2017-07-06 14:19:03
【问题描述】:

未捕获的类型错误:$ 不是函数

这是“custom-isotope-portfolio.js”文件。有谁知道怎么回事?

这是一个无字网站。主题好像有问题

enter image description here

if (!$) $ = jQuery;

// Isotope for Portfolio

$(document).ready(function() {
	('.vivaco-grid[id^="gridwrapper_"]').each( function() {
		var $div = $(this),
			token = $div.data('token'),
			settingObj = window['vsc_grid_' + token],
			$container = null,
			$optionSets = null,
			grid_gutter_width = settingObj.gutter_width;

		if (typeof settingObj === 'undefined') {
			$container = $(".grid_portfolio");
			$optionSets = $('#gridwrapper_portfolio #options .option-set');

		}else {
			$container = $(".grid_"+settingObj.id+"");
			$optionSets = $('#gridwrapper_'+settingObj.id+'  #options .option-set');

		}

		colWidth = function () {
			var w = $container.width(),
				columnNum = 1,
				columnWidth = 0;

			vals = settingObj.vals

			// apply default settings
			if (vals.grid_manager != 1) {
				if (w > 1440) {
					columnNum  = 4;

				} else if (w > 1365) {
					columnNum  = 3;

				} else if (w > 1279) {
					columnNum  = 3;

				} else if (w > 1023) {
					columnNum  = 3;

				} else if (w > 767) {
					columnNum  = 2;

				} else if (w > 479) {
					columnNum  = 2;

				}

			}else { // apply custom settings
				if (w > 1440) {
					columnNum  = vals.grid_very_wide;

				} else if (w > 1365) {
					columnNum  = vals.grid_wide;

				} else if (w > 1279) {
					columnNum  = vals.grid_normal;

				} else if (w > 1023) {
					columnNum  = vals.grid_small;

				} else if (w > 767) {
					columnNum  = vals.grid_tablet;

				} else if (w > 479) {
					columnNum  = vals.grid_phone;

				}
			}


			columnWidth = Math.floor(w/columnNum);

			$container.find('.grid-item').each(function() {
				var $item = $(this),
					gwidth = 0;

				if (vals.grid_manager == 1) {
					gwidth = grid_gutter_width;

				}

				$item.css({'margin': Math.floor(gwidth/2)});

				if ($item.hasClass('item-wide')) {
					if (w < 480) {
						$item.css({
							'width' : ((columnWidth)-gwidth) + 'px',
							'height' : Math.round(((columnWidth)-gwidth) * 0.7777777) + 'px'
						});

						$item.find('img').css({
							'width' : ((columnWidth)-gwidth) + 'px',
							'height' : '100%'
						});

					}else {
						$item.css({
							'width' : ((columnWidth*2)-gwidth) + 'px',
							'height' : Math.round(((columnWidth*2)-gwidth) * 0.7777777) + 'px'
						});

						$item.find('img').css({
							'width' : ((columnWidth*2)-gwidth) + 'px',
							'height' : '100%'
						});

					}
				}

				if ($item.hasClass('item-small')) {
					$item.css({
						'width' : ((columnWidth)-gwidth) + 'px',
						'height' : Math.round(((columnWidth)-gwidth) * 0.7777777) + 'px'
					});

					$item.find('img').css({
						'width' : ((columnWidth)-gwidth) + 'px',
						'height' : '100%'
					});

				}

				if ($item.hasClass('item-long')) {
					if (w < 480) {
						$item.css({
							'width' : ((columnWidth)-gwidth) + 'px',
							'height' : Math.round(((columnWidth)-gwidth) * 0.7777777/2) + 'px'
						});

						$item.find('img').css({
							'width' : ((columnWidth)-gwidth) + 'px',
							'height' : '100%'
						});

					}else {
						$item.css({
							'width' : ((columnWidth*2)-gwidth) + 'px',
							'height' : Math.round(((columnWidth)-gwidth) * 0.7777777) + 'px'
						});

						$item.find('img').css({
							'width' : ((columnWidth*2)-gwidth) + 'px',
							'height' : '100%'
						});

					}
				}

				if ($item.hasClass('item-high')) {
					$item.css({
						'width' : ((columnWidth)-gwidth) + 'px',
						'height' : Math.round(((columnWidth*2)-gwidth) * 0.7777777) +'px'
					});

					$item.find('img').css({
						'width' : ((columnWidth)-gwidth) + 'px',
						'height' : '100%'
					});

				}
			});

			return columnWidth;
		}

		// Isotope Call
		gridIsotope = function () {
			$container.isotope({
				layoutMode : 'masonry',
				itemSelector: '.grid-item',
				animationEngine: 'jquery',
				resizable: false,
				masonry: { columnWidth: colWidth(), gutter: 35, isFitWidth: true }
			});
		};
		gridIsotope();
		$(window).smartresize(gridIsotope);


		// Portfolio Filtering
		$optionLinks = $optionSets.find('a');

		$optionLinks.click(function() {
			var $this = $(this);
			var $optionSet = $this.parents('.option-set');

			// don't proceed if already selected
			if ( $this.hasClass('selected') ) return false;

			$optionSet.find('.selected').removeClass('selected');
			$this.addClass('selected');

			// make option object dynamically, i.e. { filter: '.my-filter-class' }
			var options = {},
				key = $optionSet.attr('data-option-key'),
				value = $this.attr('data-option-value');

			// parse 'false' as false boolean
			value = value === 'false' ? false : value;
			options[ key ] = value;

			if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
				changeLayoutMode( $this, options ); // changes in layout modes need extra logic

			} else {
				$container.isotope( options ); // otherwise, apply new options

			}

			return false;
		});
	});
});
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;

【问题讨论】:

  • 你没有加载 Jquery。
  • 这个错误意味着缺少JQuery。
  • 看截图。错误的堆栈跟踪 includes 来自 jquery.js 的调用
  • @NiettheDarkAbsol 你说得对,我没看到,但如果我愿意,我可以命名一个空脚本 jquery.js。
  • @NathanP。确实如此,但不太可能。另外,错误将更接近if(!$) $ = jQuery;(“jQuery”上的名称错误)或$(document).ready()($ 不是函数)。我的猜测是范围错误或冲突。

标签: javascript jquery wordpress


【解决方案1】:

您没有加载 jquery。尝试通过cdn加载它

【讨论】:

  • 看截图。错误的堆栈跟踪 includes 来自 jquery.js 的调用
  • sn-p 但是不包括 jquery。固定。
猜你喜欢
  • 2021-12-15
  • 2020-06-27
  • 2015-01-29
  • 1970-01-01
  • 2022-10-22
  • 1970-01-01
  • 2020-12-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多