Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.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 单击div外部的链接时,如何更改div的宽度和高度?_Javascript_Html - Fatal编程技术网

Javascript 单击div外部的链接时,如何更改div的宽度和高度?

Javascript 单击div外部的链接时,如何更改div的宽度和高度?,javascript,html,Javascript,Html,正如标题所说,当我使用JavaScript单击位于div外部的链接时,我想更改div的宽度和高度 现在,只有在使用上面的代码单击div内的任意位置时,我才能更改div的尺寸: $('.greendiv').toggle(function(){ $(this).animate({'height': '300px', 'width': '400px'}, 200); }, function(){ $(this).animate({'height': '200px', 'width': '200px'

正如标题所说,当我使用JavaScript单击位于div外部的链接时,我想更改div的宽度和高度

现在,只有在使用上面的代码单击div内的任意位置时,我才能更改div的尺寸:

$('.greendiv').toggle(function(){
$(this).animate({'height': '300px', 'width': '400px'}, 200);
}, function(){
$(this).animate({'height': '200px', 'width': '200px'}, 200);
});

下面是您需要指出要在其中执行操作的类名的

$('.clickme').toggle(function(){
    $('.greendiv').animate({'height': '300px', 'width': '400px'}, 200);
}, function(){
    $('.greendiv').animate({'height': '200px', 'width': '200px'}, 200);
});
试试这个:

$'.greendiv'.hover函数{ $this.animate{'height':'300px','width':'400px'},200; },功能{ $this.animate{'height':'200px','width':'200px'},200; }; 格林迪夫先生{ 背景:水鸭; 宽度:200px; 高度:200px; } .clickme{color:7575;}
单击我欢迎您,请不要忘记投票并接受答案