用PHP获取内部HTML [英] Get inner html with php
本文介绍了用PHP获取内部HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始学习php,遇到了这个问题。我的表单中有html代码:
I started learning php and I came accross this issue. I have the html code in my form:
<label for="u">Usability <span id='u_score'>0</span> / 7</label>
我想获取ID为u_score的范围的内部html。如何在php中做到这一点?
I want to get the inner html of the span with id u_score. How do I do this in php? Any help would be appreciated.
我已经尝试过
$u_score = $_POST["u_score"];
但这返回未定义,因为没有与范围关联的值。
but that returns undefined because there is no value associated with the span.
谢谢
推荐答案
您可以做的是将跨度文本内容复制到隐藏的输入中
What you can do is to copy the span text content into a hidden input which will be posted:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function copySpanContent() {
document.getElementById("u_score_value").value =
document.getElementById("u_score").firstChild.data;
}
</script>
</head>
<body>
<form method="POST" action="PHPSCRIPT.php" onsubmit="copySpanContent()">
<label for="u">Usability <span id='u_score'>0</span> / 7</label>
<input type="hidden" name="u_score_value" id="u_score_value">
<button type="submit">submit</button>
</form>
</body>
</html>
然后,您可以使用$ _POST ['u_score_value']从PHP获取值。
Then you can get the value from PHP with $_POST['u_score_value'].
这篇关于用PHP获取内部HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文