如果选择了某个选项,请单击按钮打开弹出框



说明

我正在制作一个网站,主要基于html,并有一个带有三个单选按钮和一个Submit Button的表单。我希望,如果用户单击"提交"按钮,pop-up box应该表示意见已提交。我是html的新手,没有找到合适的答案。CCD_ 4或CCD_。

示例代码

<form action="">
<b> What do you think is powerful on the other? </b> <br> 
<input type="radio" name="abc" value="1">Pros<br>
<input type="radio" name="abc" value="2">Cons <br>
<input type="radio" name="abc" value="3">Both are equal <br>
<input type = "Submit" value ="Submit">
</form>

这个零件的设计、位置和外观都很好。我只需要知道如何显示pop-up box按钮点击,应该说"你的意见已经提交!"。我不在乎用户选择了选项1、2还是3。这只是一种形式。

编辑

但是如果用户没有选择任何一个,那么这将是一个麻烦。如何知道用户是否没有选择任何选项。在这种情况下,弹出框应该说,"选择一个选项!">

实现这一目标的方法是什么(如果有的话(?

我想你需要这个:

<form action="">
 <b> What do you think is powerful on the other? </b> <br> 
 <input type="radio" name="abc" value="1">Pros<br>
  <input type="radio" name="abc" value="2">Cons <br>
  <input type="radio" name="abc" value="3">Both are equal <br>
  <input type="submit" onclick="return alert('Your opinion was submitted')" />
</form>

以下是演示:http://jsfiddle.net/t56GZ/4/

或者这里有另一个选择:http://jsfiddle.net/DBHEz/208/

<form action="www.google.com"onSubmit="if(!alert('Your opinion was submitted')){return false;}">
  <b> What do you think is powerful on the other? </b> <br> 
  <input type="radio" name="abc" value="1">Pros<br>
  <input type="radio" name="abc" value="2">Cons <br>
  <input type="radio" name="abc" value="3">Both are equal <br>
  <input type="submit" />
</form>

最快的选项是添加带有alert('Your opinion was submitted!')onclick属性,例如

<form action="">
<b> What do you think is powerful on the other? </b> <br> 
<input type="radio" name="abc" value="1">Pros<br>
<input type="radio" name="abc" value="2">Cons <br>
<input type="radio" name="abc" value="3">Both are equal <br>
<input type="Submit" value="Submit" onclick="alert('Your opinion was submitted!')">
</form>

或者,你可以考虑使用模态来向用户呈现一个稍微好一点的"弹出窗口"。

最新更新