简体   繁体   English

jQuery在document.ready()上无法正确运行;

[英]JQuery not running correctly on document.ready();

I have placed this inside of my jsp file: 我将其放在我的jsp文件中:

<script>
    jQuery( document ).ready(function() {
        jQuery('#resrcTypesTree').height(jQuery('.secondColumn').innerHeight() - 10);
    });
</script>

If I run this directly in Chrome's console, it works with no problems. 如果我直接在Chrome的控制台中运行此程序,则可以正常运行。 If I load the page, the #resrcTypesTree id is set to 10px (a css default). 如果我加载页面,则#resrcTypesTree ID设置为10px(默认为CSS)。 I cannot figure this out as to why it appears to not be setting the height of the resrcTypesTree to the secondColumn's height. 我不能弄清楚为什么它似乎没有将resrcTypesTree的高度设置为secondColumn的高度。 Is there something else that I am missing? 还有其他我想念的东西吗? I could put in a pause to check the page after a unit of time goes past, I just feel that is hacky. 经过一段时间后,我可以暂停一下以检查页面,我只是觉得这很麻烦。

The $ for jQuery is being overridden by another library in the project that is why I called jQuery instead of the '$'. jQuery的$被项目中的另一个库覆盖,这就是为什么我叫jQuery而不是'$'的原因。

Can someone point me in the right direction please? 有人可以指出我正确的方向吗? Thank you in advance! 先感谢您!

  • RR RR

Depending content you are targeting but as a simple fix, you should wait all content to be loaded: 根据您要定位的内容,但作为一个简单的解决方法,您应该等待所有内容被加载:

jQuery(window).on('load',function () {
    jQuery('#resrcTypesTree').height(jQuery('.secondColumn').innerHeight() - 10);
});

This ended up being an ajax issue. 这最终是一个ajax问题。 I had to write a mediator function since there are more than one ajax call being ran. 我必须编写一个中介函数,因为有多个ajax调用正在运行。 95% of the time the re-size works once put into the ajax script, however the 5% of the time, the secondary ajax call would get done first, causing the page not to re-size the gradient correctly. 将调整大小的工作一次放入ajax脚本后,有95%的时间有效,但是在5%的时间中,辅助ajax调用将首先完成,从而导致页面无法正确调整渐变的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM