【发布时间】:2014-05-06 18:21:52
【问题描述】:
我的表单中有两个按钮,一个用于回答问题,另一个用于复制问题。
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<button id="answer" onclick="document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('question').submit()">Copy the question</button>
</form>
script.php 的 URL 现在看起来像:script.php?question=sometext
现在我希望当您单击复制按钮时,URL 看起来像这样:script.php?question=sometext&copy
对于回答按钮:script.php?question=sometext&answer
编辑:
有很多答案说:“使用<input type>而不是<button>”
问题是我不能将输入字段用作按钮,因为该按钮在我的表单之外。而且我不能把它放在我的表单中
【问题讨论】:
-
为什么不使用
<input type="submit" name="copy" value="Copy..">和<input type="submit" name="answer" value="Answer...">? -
@AbcAeffchen,那么您在 URL 中什么也看不到
-
刚刚测试了一下,我得到了
script.php?question=sometext&answer=Answer+the+question -
您可以使用两个不同名称的
<input type='submit'>。它会解决你的问题。