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.
这篇关于打开页面的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:打开页面的单选按钮


- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01