Html 在 appengine 中使用带有单选按钮的“onclick”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/332766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:48:59  来源:igfitidea点击:

using "onclick" with radio button in appengine

htmlgoogle-app-engineradio-buttononclick

提问by Baltimark

Here's a code snippet. . .

这是一个代码片段。. .

<form name="FinalAccept" method="get"><br>

<input type="radio" name="YesNo" value="Yes" onclick="/accept"> Yes<br>

<input type="radio" name="YesNo" value="No" onclick="/accept"> No<br>

Clearly, what I'm trying to do is call the routine linked to /accept when the user clicks on the radio button.

显然,我想要做的是在用户单击单选按钮时调用链接到 /accept 的例程。

I know the routine is working because I call the same routine from another place in the program.

我知道该例程正在运行,因为我从程序的另一个地方调用了相同的例程。

I'm trying to run it locally using google appserver. Is there something I'm missing?

我正在尝试使用 google appserver 在本地运行它。有什么我想念的吗?

Thanks

谢谢

回答by Benry

If you want to submit the entire form when the user clicks on a radio button, then try this:

如果您想在用户单击单选按钮时提交整个表单,请尝试以下操作:

<form name="FinalAccept" method="get" action="accept"><br>
<input type="radio" name="YesNo" value="Yes" onclick="this.form.submit();"> Yes<br>
<input type="radio" name="YesNo" value="No" onclick="this.form.submit();"> No<br>
</form>

Plus, if you want to make your UI a little more user friendly, change it to this:

另外,如果你想让你的用户界面更友好一点,把它改成这样:

<form name="FinalAccept" method="get" action="accept"><br>
<input id="rYes" type="radio" name="YesNo" value="Yes" onclick="this.form.submit();">
<label for="rYes">Yes</label><br>
<input id="rNo" type="radio" name="YesNo" value="No" onclick="this.form.submit();">
<label for="rNo">No</label><br>
</form>

This will make the text "Yes" and "No" as clickable labels for their radio buttons. The user can click the label to select the radio button.

这将使文本“是”和“否”成为其单选按钮的可点击标签。用户可以单击标签来选择单选按钮。

回答by BoltBait

Your onClick event is expecting some javascript code:

您的 onClick 事件需要一些 javascript 代码:

onclick="SomeJavaScriptCode"

More here: http://www.w3schools.com/jsref/jsref_onClick.asp

更多信息:http: //www.w3schools.com/jsref/jsref_onClick.asp

So, you should be doing something like this:

所以,你应该做这样的事情:

onClick="myfunction('my value');"

EDIT: It looks like you want to go to a URL when the user clicks either "yes" or "no". To do that, you can try this little bit of javascript code:

编辑:当用户单击“是”或“否”时,您似乎想转到某个 URL。为此,您可以尝试使用以下 javascript 代码:

onClick="location.href='http://www.example.com/accept';"
onClick="location.href='http://www.example.com/decline';"

Now, if you want to submit the form automatically when the user clicks either "yes" or "no", then do what Benry suggests:

现在,如果您想在用户单击“是”或“否”时自动提交表单,请按照 Benry 的建议进行操作:

onClick="this.form.submit();"

Hope this helps.

希望这可以帮助。

回答by jamtoday

You're probably thinking of action= for the form element. onClick would just fire a javascript function.

您可能正在考虑将 action= 用于表单元素。onClick 只会触发一个 javascript 函数。