简体   繁体   English

jquery函数的类型错误

[英]Typeof error on jquery function

I'm a little new to javascript/jquery. 我对javascript / jquery有点新鲜。 I'm trying to make a function that will switch from a 200x200 image to a 400x400 image on hover. 我正在尝试制作一个在悬停时从200x200图像切换到400x400图像的功能。 Luckily, all the 200x200 images end in .200.200.jpg and all the 400x400 .400.400.jpg and are otherwise the same file path. 幸运的是,所有200x200图像都以.200.200.jpg结束,所有400x400 .400.400.jpg都是相同的文件路径。

Here's my javascript (I switched hover to trigger for testing) 这是我的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)
    });

This is the error I'm getting on console: 这是我在控制台上遇到的错误:

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'

And here for reference is an abbrebiated version of the HTML I'm trying to get at: 这里供参考的是我试图获得的HTML的缩写版本:

<div class="content">
    <ul class="ProductList =">
        <li>
            <div class="ProductImage">
                <a href="#">
                    <img src="../../...200.200.jpg" />
                </a>
            </div>
        </li>
        ...
    </ul>
</div>

keep hover , and use 保持hover ,并使用

$(this).find

instead of 代替

this.find

Can you do an on hover event, and adjust CSS via ID? 你能做一个悬停事件,并通过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 
});

I think something like this could work, if you can mess with class attributes 如果你可以搞乱类属性,我觉得这样的东西可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM