admin管理员组文章数量:1320632
I've looked accross the web but did not find an answer to this question, where does this error could came from ?
Im working on a really simple code where I just replace some text by an other.
This is the HTML
<div class="imgLittle" style="background-image:url(.jpg4fre);"</div>
<div class="imgLittle" style="background-image:url(.jpg4fre);"</div>
This is the jQuery
$(document).each('.imgLittle',function(){
newLink = $(this).css('background-image').replace(/^(.*?\.jpg).*/, "$1");
$(this).css('background-image',newLink)
})
But when I run it it e out with this output :
Uncaught TypeError: callback.apply is not a function
You can have a look there : JsFiddle.
I've looked accross the web but did not find an answer to this question, where does this error could came from ?
Im working on a really simple code where I just replace some text by an other.
This is the HTML
<div class="imgLittle" style="background-image:url(http://voyagesarabais./1874431.jpg4fre);"</div>
<div class="imgLittle" style="background-image:url(http://voyagesarabais./159431.jpg4fre);"</div>
This is the jQuery
$(document).each('.imgLittle',function(){
newLink = $(this).css('background-image').replace(/^(.*?\.jpg).*/, "$1");
$(this).css('background-image',newLink)
})
But when I run it it e out with this output :
Uncaught TypeError: callback.apply is not a function
You can have a look there : JsFiddle.
Share Improve this question edited Nov 2, 2015 at 13:59 Baldráni asked Nov 2, 2015 at 13:50 BaldrániBaldráni 5,6388 gold badges56 silver badges82 bronze badges 3-
1
.each()
wants a function as its first parameter, you're passing a string. See Alexander's answer below for the correct usage. – Paul Roub Commented Nov 2, 2015 at 13:53 -
1
$(this).css('background-image').replace(/^(.*?\.jpg).*/, "$1");
is not going to do anything FYI. The image url is not going to be updated. – epascarello Commented Nov 2, 2015 at 13:55 - @epascarello indeed, just change the function thank you all ! – Baldráni Commented Nov 2, 2015 at 13:58
1 Answer
Reset to default 8In .each
first argument should be function, like this
$('.imgLittle').each(function() {
// your code
})
Example
本文标签: javascriptUncaught TypeError callbackapply is not a functionStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: callback.apply is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742071697a2419163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论