我有一个严重的问题。我想在此表单"男性"和"女性"中添加两个字段,并将它们分配给单独的地址,例如"女性"http://female.com 和男性"http://male.com"。因此,如果您选择"类别1"并选中字段"女性",您将被重定向到页面"http://female.com/Category1",如果您选中字段"男性"和"类别1",您将被重定向到页面"http://male.com/Category1"
function Open() {
var url=document.redirect.selection.value
document.location.href=url
}
<form name="redirect">
<select name="selection">
<option value="/category1">Category1</option>
<option value="/category2">Category2</option>
</select>
<input type=button value="Go!" onClick="Open();">
</form>
试试这个
$('select').change(function(){
location = this.options[this.selectedIndex].value;
})
这只是概述可能的解决方案的快速快照。因此,如果我理解正确,您正在寻找这个。
http://jsfiddle.net/ZpMFY/show/
<script>
function Open() {
var category = document.redirect.selection.value,
domain = document.querySelector('input[name="gender"]:checked').value;;
document.location.href= domain + category;
}
</script>
<form name="redirect">
<p>
<input type="radio" name="gender" value="http://male.com" checked>Male
<input type="radio" name="gender" value="http://female.com">Female
</p>
<select name="selection">
<option value="/category1">Category1</option>
<option value="/category2">Category2</option>
</select>
<input type="button" value="Go!" onclick="Open();">
</form>
您应该注意,.queryselector() 仅适用于 IE8 和 UP