Radio Button to open pages(打开页面的单选按钮)
问题描述
我有一个带有 2 个单选按钮和一个提交按钮的表单.两个单选按钮都有不同页面的 url,比如一个会打开 google.com,另一个会打开 yahoo.com.已选择单选按钮并提交页面.我希望它打开我的网址.请帮忙.带有 HTML 和 javascript 代码.提前致谢.
i have a form with 2 radio buttons and a submit button. Both radio buttons have url of different pages, like one will open google.com and another will open yahoo.com. have selected a radio button and submit the page. i want it to open my url. Please help. with HTML and javascript code. Thanks in advance.
推荐答案
为自己节省 90k 额外脚本:
Save yourself 90k of extra script:
<script type="text/javascript">
function doSubmit(form) {
var urls = form['url'];
var i = urls && urls.length;
while (i--) {
if (urls[i].checked) {
window.location = urls[i].value;
}
}
return false;
}
</script>
<form action="" onsubmit="return doSubmit(this)">
<input type="radio" name="url" value="http://www.google.com"> Google
<input type="radio" name="url" value="http://www.yahoo.com"> Yahoo
<input type="submit" value="Submit">
</form>
哦,永远不要给表单控件命名为submit",因为它会掩盖表单的提交方法.如果必须,请将其命名为submitButton"或类似名称.
Oh, and never give a form control a name of "submit" as it will mask the form's submit method. If you must, name it "submitButton" or similar.
这篇关于打开页面的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:打开页面的单选按钮
基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
