duan051347 2012-06-18 01:52
浏览 103
已采纳

确保在调用js函数之前加载div

EDIT: iam using ajax to load text in my content that is why onload on head is not applicable.

I have an almost complete project here http://sandbox.littlegraffyx.com/bible/test2.html (enter gen 1:1 on bottom left to start)

The only problem I have is to ensure that my main div where the main text is displayed is fully loaded before I call a function that will autofit the text content on the window.

There are times that my autofit function is working and there are times it isn't and the only reason I can think of why it's not working is maybe the div isn't fully loaded yet when I call the function.

echo "<div id=\"verse\">" . $bcontent . "</div>";

echo "<script type='text/javascript'>
    scaleQuote();";
echo "</script>";

The scalequote sample is found in my other question here

Adjust size based on height (vertical length)

Here are the searches I made and I can't see how can I apply the solutions offered in these post in my case that is why I am asking one myself. Hoping I will not be down voted for "lack of research"

How do I run a function only when a div gets loaded?

getting the height and width of a div after loading info into it from an external source with jquery

thanks in advance and sorry for my english

File references

http://pastebin.com/wwQumwKJ - my JS file

http://pastebin.com/FnyST8iz - my html file

http://pastebin.com/BYfSUjQJ - my css file

Except from getting the database contents, my php file is pretty much what is posted above.

  • 写回答

3条回答 默认 最新

  • dosgy00204 2012-06-18 02:43
    关注

    Short answer

    Inside your MovePrevious() function, add scaleQuote(); inside the Ajax's callback:

    document.getElementById("versePlace").innerHTML=xmlhttp.responseText;
    scaleQuote(); //<-- here
    

    Long Answer

    You're using standard JS on your Ajax calls. Standard Ajax calls such as yours, which simply places the response HTML inside an element with innerHTML does not execute any script tags inside of the response text. It's different than jQuery's append/appendTo methods, which parse any script tags inside of your response text and executes it upon being added to the DOM.

    Why does it work "most of the time" then?

    Because your MoveNext() function already has a scaleQuote(); function call inside of its callback.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿