[英]Typeof error on jquery function
我对javascript / jquery有点新鲜。 我正在尝试制作一个在悬停时从200x200图像切换到400x400图像的功能。 幸运的是,所有200x200图像都以.200.200.jpg结束,所有400x400 .400.400.jpg都是相同的文件路径。
这是我的javascript(我切换悬停触发测试)
$('.Content .ProductList li').trigger(function(){
var ImageSRC = this.find(".productimage a img").attr('src');
NewImageSRC = ImageSRC.replace('.200.200.jpg','.400.400.jpg');
this.find(".productimage a img").attr('src', NewImageSRC)
});
这是我在控制台上遇到的错误:
TypeError: Object function (){ var ImageSRC = this.find(".productimage a img").attr('src'); NewImageSRC = ImageSRC.replace('.200.200.jpg','.400.400.jpg'); this.find(".productimage a img").attr('src', NewImageSRC) } has no method 'indexOf'
这里供参考的是我试图获得的HTML的缩写版本:
<div class="content">
<ul class="ProductList =">
<li>
<div class="ProductImage">
<a href="#">
<img src="../../...200.200.jpg" />
</a>
</div>
</li>
...
</ul>
</div>
保持hover
,并使用
$(this).find
代替
this.find
你能做一个悬停事件,并通过ID调整CSS吗?
$( ".img200pxclass" ).hover(function() {
$(this).attr('src','400px.png');
$(this).switchClass( "img200px", "img400px");
$(this).css("height", "400px"); //same for width ; except, updating class might do this for you if you want
});
如果你可以搞乱类属性,我觉得这样的东西可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.