当我用 JS 提交表单时。找不到任何值。
这是我的代码:
<!-- Form file -->
<form id="postnotes" name="postnotes" action="./mechanic/comments.php" method="post">
<textarea id="comments" class="comments" rows="4" name="comment" cols="50" placeholder="Make a note"></textarea>
</form>
<script type="text/javascript">
$(function() {
$('textarea#comments').on('keyup', function(e) {
if (e.which == 27 && ! e.shiftKey) {
document.getElementById("postnotes").submit();
}
});
});
</script>
<!-- file comments -->
<?php if(isset($_POST['postnotes'])){
echo 'hello its me your looking for';
}
else{echo 'nope srry';}
?>
谁能帮帮我。
提前致谢!
最佳答案
提交很好,尽管当用户按下 Esc 时提交似乎很奇怪。这是 PHP 检查不正确的提交。您正在寻找一个使用表单 名称的字段(postnames
)。它是发送的字段的名称(comment
,textarea
的name
),例如查看 $_POST["comment"]
,而不是 $_POST["postnames"]
。
关于javascript - js提交没有值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40933361/