动态潜水高度jQuery.Load()不工作
Dynamic Div Height jQuery.Load() not working
我正试图根据jQuery.load()加载到div容器中的内容动态更改div容器的高度。我尝试了许多不同的代码排列方式,在这里搜索和查看了许多帖子,并阅读了jQuery上的文档。如果我在页面加载后在firebug控制台中运行我的函数,但当代码保存并与页面一起加载时,我的函数就不起作用了。如果脚本是由页面运行的,控制台会为所有表的高度输出"0",但当我在firebug中运行它时,它会给出适当的高度。
代码如下。基本上,这是一个用户定义的页面,我在其中粘贴了这个脚本,div#element4位于jQuery的一个jQuery选项卡中。你能在我的代码中发现一个错误吗?或者帮我让它正常工作吗?
$("#element4").load("<dbid>?act=API_GenResultsTable&qid=8", function(response, status, xhr) {
if (status == "success") {
$('#element4 table').each( function(x, y){
var max_height = 0;
var yHeight = $(y).height();
max_height = ( yHeight > max_height) ? yHeight : max_height;
$('#element4').height(max_height);
console.log(max_height);
});
}
});
您正在为每个table
将max_height
重置为零。尝试将其从each
循环中移出,并最终设置高度:
var max_height = 0; // init max
// find tallest table
$('#element4 table').each(function(x, table) {
var yHeight = $(table).height();
max_height = (yHeight > max_height) ? yHeight : max_height;
});
$('#element4').height(max_height); // set height
console.log(max_height);
在使用$("#tabs").tabs()创建选项卡之前,我使用$.load()加载外部内容,从而找到了解决此问题的方法;。然后我使用了类似于上面发布的脚本。。这是最后一次运行。所以加载内容,创建选项卡,调整div的大小。
$('#ELEMENTID table').each(function (x, y) { //find table heights in the <div>
var max_height = 0;
var yHeight = $(y).innerHeight();
max_height = (yHeight > max_height) ? yHeight : max_height;
var compHeight = max_height + 24; //adding 24 because it was the standard height for the smallest of 3 tables..
$('#element3').height(compHeight);
console.log(compHeight);
如果有人有更好的解决方案,我们将不胜感激。
相关文章:
- .load ajax无法正常工作whitin wordpress主题
- 动态潜水高度jQuery.Load()不工作
- Ajax load在chrome中不起作用,而在Fire fox中工作
- 为什么onload=“;函数“;工作,而jquery.load不工作;t
- jQuery.load随机工作,绝望
- Jquery 和 JS 在 DOM 上工作,而不是在 load
- 在 .detach() 和 .append() 之后使用 .load() 无法按预期工作
- 如何在没有window.location.reload()的情况下使JavaScript .load工作
- jquery .load() 函数仅在第一次工作
- 当我将变量附加到 URL 时,如何使 .load 工作
- 刷新页面时使用chrome缓存的图像.load()工作不正常
- 为什么不'第二次和第三次调用后,t ajax load()工作
- jQuery.load()是如何工作的
- load()由一个不工作的按钮触发
- jQuery.load()无法在jQueryload()加载的另一个内容中工作
- Ajax .load()在初始触发时无法工作
- 试图获得一个AJAX风格的.load()元素与.on()绑定,但它不工作
- jQuery .on('load')没有按预期工作
- Jquery load()只在firefox中工作
- Javascript stoppropagation不能与ajax .load一起工作