扫码关注官方订阅号
代码结构类似于这样
我想点击里面的iframe改变父元素“iframe_p”的相关样式,比如高宽什么的要怎么做?谢谢
学习是最好的投资!
$("iframe").click(function(){ $(".iframe_p").style.height="100px"; $(".iframe_p").style.width="100px"; )
$("iframe").click(function(){ $(this).parent().css('height', 'xxpx'); $(this).parent().css('width', 'yypx'); }); 父元素的话可以用.parent() 如果是其它元素也可以各种用选择器去选。 但我看过一本叫《编写可维护的Javascript》还是什么的书,里面有说js里面最好不要直接操作css,要改变样式可以通过class 就是说把上面的回调函数内容换成 $(this).parent().addClass('xxClass'); $(this).parent().removeClass('yyClass'); 之类的 然后样式定义在css里面 .xxClass{ 样式 } 反正我挺喜欢这样的也说一下你可以参考参考~( ̄▽ ̄)~
在里面的iframe call window.parent
1楼正解
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
$("iframe").click(function(){
$(this).parent().css('height', 'xxpx');
$(this).parent().css('width', 'yypx');
});
父元素的话可以用.parent()
如果是其它元素也可以各种用选择器去选。
但我看过一本叫《编写可维护的Javascript》还是什么的书,里面有说js里面最好不要直接操作css,要改变样式可以通过class
就是说把上面的回调函数内容换成
$(this).parent().addClass('xxClass');
$(this).parent().removeClass('yyClass');
之类的
然后样式定义在css里面
.xxClass{
样式
}
反正我挺喜欢这样的也说一下你可以参考参考~( ̄▽ ̄)~
在里面的iframe call window.parent
1楼正解