0

I have code that looks like this:

<?php
    for ($i = 0; $i < count($keyArray); $i++) {
?>
<form action="" method="POST">
    <th>
        <a href="#" onclick="$(this).closest('form').submit()">
        <?php echo $keyArray[$i] ?></a>
    </th>
    <input type="hidden" name="tableHeader" value="<?php echo $keyArray[$i]; ?>">
</form>
<?php } ?>

I'm trying to submit the form through a link. To test the form, I use:

echo "<pre>";
print_r($_POST);
echo "</pre>";

I've tried using a button type submit, and it works. I don't know what's wrong with the jQuery in my onclick, but the info is not being sent.

4

2 回答 2

1

可能是如果您为表单提供 ID 并在 jQuery 命令中使用它:

<form id="form<?php echo $i ?>" action="" method="POST">
<th><a href="#" onclick="$('#form<?php echo $i ?>').submit()"><?php echo $keyArray[$i] ?></a></th>
<input type="hidden" name="tableHeader" value="<?php echo $keyArray[$i]; ?>">
</form>
于 2013-07-11T19:59:43.563 回答
1

为什么你不只是添加一个提交按钮而不是一个带有 jQ​​uery 触发器的锚?

<input type="submit" id="submit-btn" value="<?php echo $keyArray[$i] ?>">

如果你想要它像一个锚,你可以使用 CSS :

#submit {
    background: transparent;
    color: blue;
}
于 2013-07-11T20:09:21.093 回答