Moh*_*aji 11 css jquery document-ready window-load
我用下面的代码有相同的高度rightpos,leftpos并middlepos申报单:
<script>
jQuery.noConflict();
jQuery(document).ready(function($){
// Find the greatest height:
maxHeight = Math.max($('#rightpos').height(), $('#middlepos').height());
maxHeight = Math.max(maxHeight, $('#leftpos').height());
// Set height:
$('#rightpos').height(maxHeight);
$('#middlepos').height(maxHeight);
$('#leftpos').height(maxHeight);
})
</script>
Run Code Online (Sandbox Code Playgroud)
使用这种方式为http://yaskawa.ir/的主页确定最高的div 在Firefox中运行良好,但在Chrome中有问题.
Sparky672回答后更新1:
我可以看到,使用此代码,alert('test here');最后不起作用.
<script>
jQuery.noConflict();
//jQuery(document).ready(function($){});
jQuery(window).load(function($){
// Find the greatest height:
maxHeight = Math.max($('#rightpos').height(), $('#middlepos').height());
maxHeight = Math.max(maxHeight, $('#leftpos').height());
// Set height:
$('#rightpos').height(maxHeight);
$('#middlepos').height(maxHeight);
$('#leftpos').height(maxHeight);
alert('test here');
})
</script>
Run Code Online (Sandbox Code Playgroud)

Spa*_*rky 20
尝试window.load()代替document.ready()确保在计算高度之前加载所有资产.
jQuery(window).load(function($){
Run Code Online (Sandbox Code Playgroud)
文档:
当load和所有子元素已完全加载时,load事件将发送到元素.此事件可以发送到与URL关联的任何元素:图像,脚本,框架,iframe和窗口对象.
http://api.jquery.com/load-event/
见DEMO:
| 归档时间: |
|
| 查看次数: |
10534 次 |
| 最近记录: |