PHP:标记对象

发布于 2024-11-26 21:58:59 字数 430 浏览 2 评论 0原文

我有一个带有名称的对象,我想知道如何标记它,例如在 Javascript 中,您将放置

getElementByID("ElementHere")

您将如何在 PHP 中执行此操作?这就是我所拥有的:

<HTML>
<HEAD>
<BODY>
<FORM method="POST" name="passcheck">
Blah blah blah...
</FORM>
<?php
$obj = this.document:getElementByID("passcheck")
?>
</BODY>
</HEAD>
</HTML>

这在 PHP 中是否可能?

另外,如果您想出答案,能否举例说明?

谢谢

I have an object, with a name, and I am wondering how to tag it, in Javascript for example, you would put

getElementByID("ElementHere")

How would you do this in PHP? This is what I have:

<HTML>
<HEAD>
<BODY>
<FORM method="POST" name="passcheck">
Blah blah blah...
</FORM>
<?php
$obj = this.document:getElementByID("passcheck")
?>
</BODY>
</HEAD>
</HTML>

Would this be possible somehow in PHP?

Also, if you come up with an answer, could you please show it as an example?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗳卜坏 2024-12-03 21:58:59

document.getElementById(注意Id不是ID)将通过其ID而不是其名称来获取元素。将 name 属性替换为 id 属性。如果您确实想使用名称属性,那么您需要循环getElementsByName

在 PHP 中,如果您只是输出嵌入了 PHP 的 HTML,那么您无法修改文档的任意点 — 只能修改那些具有显式 PHP 代码的位置 — (除非可以打开输出缓冲并然后修改缓冲区的内容,但如果这是可能的,那就太疯狂了,无论如何你最好重新构建系统)。

给定一个单独的 HTML 文档,那么您只需将其加载到 DOM 引擎 中,然后您就可以使用 标准 DOM 方法 其工作方式与 JavaScript 中的工作方式相同。

document.getElementById (note Id not ID) will get an element by its id, not by its name. Replace the name attribute with an id attribute. If you really want to use a name attribute then you would need to loop over getElementsByName.

In PHP, if you are simply outputting the HTML with embedded PHP in it, then you can't modify arbitrary points of the document — only those where you have explicit PHP code in place — (unless it is possible to turn output buffering on and then modify the contents of the buffer, but if that is possible then it is madness and you would be better off re-architecting the system anyway).

Given a separate HTML document, then you just need to load it into a DOM engine and then you can use standard DOM methods which work in the same way as they do from JavaScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文