我有一个隐藏的输入字段,我使用jquery填充一些任意值,这样:
function foo() {
// Obtains the contents of a div within the current page
var $elem = $("#something").html();
// Places the contents of the div into a hidden input field
$("#hidden").val($elem);
}
在调试这个东西时,我可以看到elem变量从所需的div中获取html,而不是变量是否传递给隐藏的输入字段值 .
我有一个表格:
<form method="POST" action="file.php" target="_blank">
<input id="hidden" type="hidden" value=""/>
<input type="submit" onmouseover="foo()" value="Download"/>
</form>
提交时执行file.php:
<?php
$html = $_POST["hidden"];
echo $html;
?>
echo调用什么都不返回,我得到的只是一个空白页面 . 我想知道为什么隐藏输入字段的值没有被更改,或者为什么在POST调用期间没有传递它 .
进一步的实验表明,即使我用一些随机值设置隐藏字段的值:
<input id="hidden" type="hidden" value="Some Value"/>
在执行PHP文件时仍然无法获取它 . echo调用什么都不返回 . 我获取此隐藏输入字段的值有什么问题?我曾经非常谨慎地使用过PHP,但过去在提交POST时从表单中获取值并没有问题 .
2 回答
您需要为输入字段命名,以便使用$ _POST在php中访问它
您应该只指出
name
属性