简体   繁体   English

XHTML / JS OnClick单选按钮需要根据select中的选项值导航到另一个页面

[英]XHTML/JS OnClick radio button need navigate to another page based on option value in select

I am using a select options dropdown and a couple of radio button inputs in my xhtml pages. 我在xhtml页面中使用了选择选项下拉菜单和几个单选按钮输入。 I have already written code under select element so that when the user chooses an option from the select element, the onchange attrribute in it will take it to another page as displayed in options value. 我已经在select元素下编写了代码,以便当用户从select元素中选择一个选项时,其中的onchange属性将把它带到显示在options值中的另一页。

However, I need a similar behaviour with radio button input too. 但是,我也需要单选按钮输入有类似的行为。 So, when a user clicks any button, I need it to get the value from the already selected option and navigate to that page. 因此,当用户单击任何按钮时,我需要它来从已选择的选项中获取值并导航到该页面。

How can I achieve this? 我该如何实现?

<select id="color" onchange="location = this.options[this.selectedIndex].value+'?view=calView';">
    <option value="page1.htm">Page1</option>
    <option value="page2.htm">page2</option>
    <option value="page3.htm">Page3</option>
</select>
<input id="cal" name="view_opt" value="calView" type="radio" />
<label for="cal">Calendar View</label>
<input id="list" name="view_opt" value="listView" type="radio" />
<label for="list">List View</label>

是的,应该可以正常工作或使代码更通用,在onclick函数中传递此值,并在单个函数中处理所有巡回任务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM