我有一个隐藏的输入字段,我使用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,但在过去,在提交帖子时从表单中获取值没有问题。
发布于 2013-01-07 07:21:45
您需要输入字段的名称,才能使用$_POST在php中访问它
<input id="hidden" name="hidden" type="hidden" value=""/>发布于 2013-01-07 07:21:40
您应该只指定name属性
<form method="POST" action="file.php" target="_blank">
<input name="hidden" id="hidden" type="hidden" value=""/>
<input type="submit" onmouseover="foo()" value="Download"/>
</form>https://stackoverflow.com/questions/14187871
复制相似问题