[英]Uncaught TypeError: $(…).sidr is not a function[Console Chrome developer tool]
I put this code into add basic module HTML block of a wordpress page builder. 我将此代码放入wordpress页面构建器的添加基本模块HTML块中。 I encounter the white screen of death.
我遇到死亡的白屏。 Chrome developer console told me the following:
Chrome开发者控制台告诉我以下内容:
helpers.js?ver=4.5.3:15 Uncaught TypeError: $(...).sidr is not a function
This can be traced from line 15 in helpers.js?ver=4.5.3: 可以从helpers.js?ver = 4.5.3的第15行进行追踪:
$('#mobile-menu-trigger').sidr({
source: sourceVal,
name: 'sidr-main'
});
Before or after I restored the previous version of the page, there was no such error. 在还原页面的先前版本之前或之后,没有此类错误。 The html code below seems to run normally if save as a html file and open it with chrome.
如果另存为html文件并使用chrome打开,则以下html代码似乎可以正常运行。 Can someone please explain which might have possibly caused that error?
有人可以解释可能导致该错误的原因吗?
Edit: When I change the theme of wordpress, everything works again. 编辑:当我更改wordpress的主题时,一切都会再次起作用。 With all of other themes, the code works so the problem should come from the theme.
在所有其他主题下,代码都可以正常工作,因此问题应该出在主题之外。
$(document).ready(function() { getUpdates(); }); function getUpdates() { // get the data with a webservice call $.getJSON('http://api.thingspeak.com/channels/136053/feed/last.json?callback=?', function(data) { // if the field1 has data update the page if (data.field1) { document.querySelector('.info-giver .temperature').innerHTML = data.field1.slice(0,4) + "°C"; document.querySelector(".info-giver .humidity").innerHTML = data.field2.slice(0,5) + "%"; document.querySelector('.info-giver .windspeed').innerHTML = data.field4.slice(0,4) +" m/s"; document.querySelector(".info-giver .pressure").innerHTML = data.field3 +"Pa" ; } }); } (jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class = "announcer"> <div class="temperatureDeclared" style= "width: 25.00%">Temperature</div> <div class="humidityDeclared" style= "width: 25.00%">Humidity</div> <div class="windspeedDeclared" style= "width: 25.00%">Windspeed</div> <div class="pressureDeclared" style= "width: 25.00%">Pressure</div> </div> <div class = "info-giver"> <div class="temperature" style= "width: 25.00%">N/a</div> <div class="humidity" style= "width: 25.00%">N/a</div> <div class="windspeed" style= "width: 25.00%">N/a</div> <div class="pressure" style= "width: 25.00%">N/a</div> </div>
You didn't include your sidr library. 您没有包括sidr库。 After loading jquery include sidr library.
加载jquery后,包括sidr库。 After that init sidr like this on your html.
之后,在您的html上像这样初始化sidr。
$('#mobile-menu-trigger').sidr({....});
Add these lines before and after code your code will works 在代码之前和之后添加这些行,您的代码将可用
;(function($){
//code
})(jQuery);
Just Like This 像这样
;(function($){
$('#mobile-menu-trigger').sidr({
source: sourceVal,
name: 'sidr-main'
});
})(jQuery);
I hope this will works ! 我希望这会成功!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.