【发布时间】:2015-02-28 19:46:43
【问题描述】:
是否可以通过单击 div 元素来提交表单,就好像它是通过提交按钮提交的一样?
让这个 PHP 工作:
if(isset($_POST["share"])) { /* do something*/ }
表格:
<form id="form" action="publish.php" method="POST">
<textarea name="description" maxlength="500">Description...</textarea>
<input type="submit" name="share" value="Share" />
</form>
这不会发布共享值 $_POST['share']。
if($(".post-form").length){
$(".post-form").click(function(event) {
$("#form").submit();
return false;
});
}
【问题讨论】:
-
看看jquery
submit()方法。 api.jquery.com/submit -
阅读下面的 cmets。这没有帮助
-
share是input和type = "submit"。你想从那里得到什么?这就是为什么$_POST['share']没有设置的原因,我猜。您可能想改用$_POST['description']?