【问题标题】:In PHP, how do you access the dom and print out its nodeValue or value in general using the querySelector method?在 PHP 中,如何使用 querySelector 方法访问 dom 并打印出它的 nodeValue 或值?
【发布时间】:2020-10-11 01:26:51
【问题描述】:
<input id="button01" type="button" value="add" onclick="add()">7</input>
<input id ="button02" type="button" value="sub" onclick="sub()">8</input>
<input id="button03" type="button" value="div" onclick="div()">9</input>
<input id="button04" type="button" value="0" name="button04">10</input>
<?php

$document->querySelector('#button04')->nodeValue;
?>

我想使用 querySelector,老实说,我不想要关于 Ajax 的答案,我只想回应 nodeValue 和 button04 的值。谢谢。

【问题讨论】:

  • PHP 是一种服务器端语言。它任何输出被提供给浏览器之前运行。因此 PHP 将永远无法从 DOM 中选择值并显示它们。如果您不希望网站刷新,Ajax 是您唯一的选择。如果这样做,则必须将值作为表单提交并将它们保存在变量或会话/cookie 中以从那里检索它们

标签: php dom jquery-selectors


【解决方案1】:

您可以使用 jQuery 访问按钮的值

$('#button04').val();

要访问节点值,您可以使用以下命令:

$('#button04').text();

【讨论】:

  • 最终我试图将该值分配给一个 php 变量,以便我可以跨页面移动它。这可能吧?
  • does ---$document->querySelector('#button04')->nodeValue;--- 没有针对这种情况注册任何建议?
猜你喜欢
  • 2015-02-15
  • 2012-09-05
  • 2011-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多