php加载到'html body'之前吗? [英] Does php load BEFORE the 'html body'?

查看:86
本文介绍了php加载到'html body'之前吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难解释这个问题,但我目前正在将php页面中的变量传递给一些html隐藏输入。

Difficult to explain this Question, but im currently passing variables in a php page to some html hidden inputs.

我用javascript从隐藏的输入中获取这些值功能。这个函数被调用如下:

Im fetching those values from the hidden inputs with a javascript function. This function gets called like this:

 <body onload="function();">

它现在可以在我的系统上运行,但是有可能从php传递的值可能无法获得通过因为body已经调用函数BEFORE之前php代码设置隐藏的输入类型?

It works on my system now, but is there any chance that the value passed from php might not get through because body has called the function BEFORE the php code sets the input type hidden?

谢谢

推荐答案

可能混淆了哪一部分做了什么。

You have may have mixed up which part does what.


  • PHP在服务器端生成HTML页面 。当HTML页面到达浏览器时,PHP已经完成了它的工作。 PHP在呈现HTML后无法执行某些操作。

  • PHP generates the HTML page on the server side. When the HTML page arrives at the browser, PHP has done its job. There is no way for PHP to do something after it has rendered the HTML.

Javascript在用户浏览器中执行 后,页面已生成并加载。 (或者在期间;正如theraccoonbear指出的那样,Javasript可以在页面完全加载之前在浏览器中运行。)

Javascript is executed in the user's browser after the page has been generated and loaded. (Or during; as theraccoonbear points out, Javasript can run in the browser before the page has loaded completely.)

Javascript命令无法与PHP通信脚本渲染页面,因为当Javascript进入游戏时,PHP已经消失。

A Javascript command can not communicate with the PHP script rendering the page, because when Javascript comes into play, PHP is already gone.

所以答案问题是:不,在PHP完成之前,JS函数无法执行。正如几位评论员指出的那样,这并不完全正确。在输入HTML元素之前,Javascript 可能开始行动。但是,在您的示例中,Javascript仅在文档完全加载时触发。在那个星座中,答案是否定的,不可能发生。

So the answer to your question is: No, the JS function can not execute before PHP is done. As several commentators point out, that is not entirely true. A Javascript could come into action before the input HTML elements have been rendered. In your example however, the Javascript triggers only when the document is completely loaded. In that constellation, the answer is no, it can't happen.

这篇关于php加载到'html body'之前吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆