Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery函数上的错误类型_Javascript_This_Jquery - Fatal编程技术网

Javascript jquery函数上的错误类型

Javascript jquery函数上的错误类型,javascript,this,jquery,Javascript,This,Jquery,我对javascript/jquery有点陌生。我正在尝试创建一个函数,该函数将在悬停状态下从200x200图像切换到400x400图像。幸运的是,所有200x200图像都以.200.200.jpg和所有400x400.400.400.jpg结尾,并且在其他方面都是相同的文件路径 这是我的javascript(我将悬停切换为触发器进行测试) 这是我在控制台上遇到的错误: TypeError: Object function (){ var ImageSRC = this.find(".produ

我对javascript/jquery有点陌生。我正在尝试创建一个函数,该函数将在悬停状态下从200x200图像切换到400x400图像。幸运的是,所有200x200图像都以.200.200.jpg和所有400x400.400.400.jpg结尾,并且在其他方面都是相同的文件路径

这是我的javascript(我将悬停切换为触发器进行测试)

这是我在控制台上遇到的错误:

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>

  • ...

保持
悬停
,并使用

$(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 
});

我认为,如果你能搞乱类属性的话,这种方法可能会奏效。在这种情况下,触发器是没有意义的。你从什么换成了触发器。触发器是它不工作的原因。我从.hover()切换过来的原因是我没有试图更改CSS值。我正在尝试更改为其他图像文件。
.attr
img src
更改为其他文件。
$( ".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 
});