Javascript 设置iFrame的高度
我试过这个:Javascript 设置iFrame的高度,javascript,jquery,css,Javascript,Jquery,Css,我试过这个: $('#my_ifr').css('height', '5px !important'); 这是: $('#my_ifr').height(5); 但规模保持不变。当我写作时: $('#my_ifr').height(); 在cosole中,我得到了5,但是当我在Goog中检查元素时,你必须设置他的高度属性 $('#my_ifr').attr('height', '5'); 这个很好用 $('#my_ifr').css('height', '500'); 检查这个,它工作
$('#my_ifr').css('height', '5px !important');
这是:
$('#my_ifr').height(5);
但规模保持不变。当我写作时:
$('#my_ifr').height();
在cosole中,我得到了5,但是当我在Goog中检查元素时,你必须设置他的
高度
属性
$('#my_ifr').attr('height', '5');
这个很好用
$('#my_ifr').css('height', '500');
检查这个,它工作正常
$('#iframeID').css({'height':'500px'});
但是,你想增加tinymce高度意味着
你这样用,
tinyMCE.init({
...
height : "500"
});
两个答案(@yogi和@Mihai Iorga)都很正确,但看起来你的答案。。。。有几点值得评论:
您没有触发该功能。。。加:
$(function() {
// Handler for .ready() called.
});
或
(是一样的…)
现在。。。另一件事是在你的JSFIDLE中,没有iframe#我的ifr
请尝试此更新:
在设置css height属性之前,您需要加载Iframe的内容。 否则,它将保持未定义状态,并且您无法更改height属性 工作代码
setInterval(function(){if(typeof($('#mce_0_ifr').css('height'))=='undefined'){}else{$('#mce_0_ifr').css('height','50px');}},0);
您的html是什么样子的?(请:)@JeroenMons我有一个简单的html,里面有tinymce。你能提供一个解决你问题的方法吗?@JeroenMons你想把它的高度设置为5px是什么?中间的白色文本区域?
$(document).ready(function() {
// Handler for .ready() called.
});
$(function() {
// Not Valid
//$('#mce_0_ifr').height(5);
// Valid - by @yogi
$('#my_ifr').css('height', '500');
// Valid - by @Mihai Iorga only if no attr was previulsy set
// but be carefull because pre-defined element.style or css rule
// will overright the atribute (attr)
$('#my_ifr').attr('height', '5');
// That is, the iframe will have 500 and not 5
});
setInterval(function(){if(typeof($('#mce_0_ifr').css('height'))=='undefined'){}else{$('#mce_0_ifr').css('height','50px');}},0);