jQuery Autosize plugin error - intermediate value(…) is not a function

a 夏天 提交于 2019-12-29 12:11:55

问题


I use jQuery Autosize plugin:

http://www.jacklmoore.com/autosize/

The script itself you can see here:

http://www.jacklmoore.com/js/jquery.autosize.js

This is how I use the script:

jQuery(function($){$(document).ready(function(){
$('textarea').autosize();
}

Problem N 1

Just updated the script to the latest version and it stopped to work:

"TypeError: (intermediate value)(...) is not a function"

Javascript console reports this error on the last line of the script:

}(window.jQuery || window.$)); 

Problem N 2

Script doesn't work in modal windows (PrettyPhoto) and javascript console doesn't show any errors.

Any ideas?


回答1:


the "TypeError: (intermediate value)(...) is not a function" pops up as the result of missing a semi colon on the function BEFORE the one it throws an error on. It might be as simple as:

jQuery(function($){$(document).ready(function(){
$('textarea').autosize();
}  
); //<-----

or it could be the function declared before that. An example of how this is cause is in this code:

var populate = function(sw) {
  myglobalswitch = sw;
  window.setTimeout(repopulate, 250, sw);
}

(function( $ ) {
$.widget( "custom.combobox", {
_create: function() {
....
})( jQuery );

results in the Intermediate value is not... on the last line: })( jQuery );

However, the fix is adding a semi colon to the populate function:

var populate = function(sw) {
  myglobalswitch = sw;
  window.setTimeout(repopulate, 250, sw);
}  ;

to prevent the parser from thinking that "var populate = ... " and (function($) ... are a single statement, the second extending from the first.




回答2:


FWIW the autosize invocation method has changed. If you end up here and are using it with jQuery

Previously it was

$('textarea').autosize();

The new invocation is

autosize($('textarea'));



回答3:


You may have declared a function, inside a function, after you needed it. This was my problem.



来源:https://stackoverflow.com/questions/23370269/jquery-autosize-plugin-error-intermediate-value-is-not-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!