Dav*_*unt 0 html javascript php forms post
我有一个隐藏的输入字段,我使用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);
}
Run Code Online (Sandbox Code Playgroud)
在调试这个东西时,我可以看到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>
Run Code Online (Sandbox Code Playgroud)
提交时执行file.php:
<?php
$html = $_POST["hidden"];
echo $html;
?>
Run Code Online (Sandbox Code Playgroud)
echo调用什么都不返回,我得到的只是一个空白页面.我想知道为什么隐藏输入字段的值没有被更改,或者为什么在POST调用期间没有传递它.
进一步的实验表明,即使我用一些随机值设置隐藏字段的值:
<input id="hidden" type="hidden" value="Some Value"/>
Run Code Online (Sandbox Code Playgroud)
在执行PHP文件时仍然无法获取它.echo调用什么都不返回.我获取此隐藏输入字段的值有什么问题?我曾经非常谨慎地使用过PHP,但过去在提交POST时从表单中获取值并没有问题.
您需要为输入字段命名,以便使用$ _POST在php中访问它
<input id="hidden" name="hidden" type="hidden" value=""/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
141 次 |
| 最近记录: |