Dan*_*ats 3 javascript php forms post
我有两个文件,(file1和file2).file1包含PHP include语句中的file2.File1还包含一个表单并打印出所有$ _POST变量.File2使用Javascript按钮动态更改输入字段中的值.问题是按下提交后$ _POST为空.为什么这样,我该如何解决?
文件1:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php include 'file2.php'; ?>
<input type="submit" /></form>
<?php foreach ($_POST as $key => $val) { echo $key . " belongs to " . $val; } ?>
Run Code Online (Sandbox Code Playgroud)
文件2
<script type="text/javascript">
var button = {
counter : 0,
count : function() {
text = document.getElementById("text");
this.counter++;
text.setAttribute("value", this.counter);
}
};
</script>
<button type="button" onclick="button.count()">CLICK ME!</button>
<input id="text" type="text" value="0" />
Run Code Online (Sandbox Code Playgroud)
你忘了设置name属性:
<input id="text" name="text" type="text" value="0" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1488 次 |
| 最近记录: |