我有2个下拉列表,第二个选项取决于第一个选择。我在OSX上,并且在Chrome和FF中工作正常,但仅在Safari中,第二个下拉列表显示了所有选项,而不是从第一个下拉列表中选择的选项。
我似乎仅在Safari中找不到有关此类问题的任何信息。这是我的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js" language="JavaScript" type="text/javascript"></script>
<style type="text/css">
.subcat option{
display:none;
right: 10px;
}
.subcat option.label{
display: inline;
}
.select {
position: relative;
display: inline-block;
margin-bottom: 15px;
width: 262px;
margin: 0 20px 0 0;
}
.select select {
font-family: Overpass, Arial, Helvetica, sans-serif;
font-size: 18px;
display: inline-block;
width: 100%;
cursor: pointer;
padding: 15px 20px;
outline: 0;
border: 1px solid #ccc;
border-radius: 0px;
background: none;
color: #666666;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
}
.select select::-ms-expand {
display: none;
}
.select select:hover,
.select select:focus {
color: #000000;
background: none;
}
.select select:disabled {
opacity: 0.5;
pointer-events: none;
}
.select_arrow {
position: absolute;
top: 16px;
right: 25px;
width: 10px;
height: 10px;
border: solid #df0700;
border-width: 0 2px 2px 0;
display: inline-block;
padding: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
z-index: -99;
}
.select select:hover ~ .select_arrow,
.select select:focus ~ .select_arrow {
border-color: #df070;
}
.select select:disabled ~ .select_arrow {
border-top-color: #cccccc;
}
</style>
<script>
function goToNewPage()
{
var url = document.getElementById('store').value;
console.log(url);
if(url != 'none') {
window.location = url;
}
}
</script>
</head>
<body style="width: 773px">
<form style="margin: 40px 0" id="formname" name="Sate-Store">
<div class="select">
<select name="state" id="state">
<option value="">Select state</option>
<option value="ma">MA</option>
<option value="me">ME</option>
<option value="nh">NH</option>
</select>
<div class="select_arrow">
</div></div>
<div class="select">
<select disabled="disabled" class="subcat" id="store" name="store">
<option value>Select a store</option>
<!-- MA -->
<option rel="ma" value="ma_store_1">MA Store 1</option>
<option rel="ma" value="https://www.google.com">MA Store 2</option>
<option rel="ma" value="ma_store_3">MA Store 3</option>
<option rel="ma" value="ma_store_4">MA Store 4</option>
<option rel="ma" value="ma_store_5">MA Store 5</option>
<!-- ME -->
<option rel="me" value="me_store_1">ME Store 1</option>
<option rel="me" value="me_store_2">ME Store 2</option>
<option rel="me" value="me_store_3">ME Store 3</option>
<option rel="me" value="me_store_4">ME Store 4</option>
<option rel="me" value="me_store_5">ME Store 5</option>
<!-- MH -->
<option rel="nh" value="nh_store_1">NH Store 1</option>
<option rel="nh" value="nh_store_2">NH Store 2</option>
<option rel="nh" value="nh_store_3">NH Store 3</option>
<option rel="nh" value="nh_store_4">NH Store 4</option>
<option rel="nh" value="nh_store_5">NH Store 5</option>
</select>
<div class="select_arrow">
</div></div>
<input type=button value="Start shopping" onclick="goToNewPage()" style="font-family: Overpass, Arial, Helvetica, sans-serif; font-size: 18px;
display: inline-block;
width: 197px;
cursor: pointer;
padding: 15px 20px 13px;
outline: 0;
border: 1px solid #ccc;
border-radius: 0px;
background: #df0700;
color: #fff;" />
</form>
<script type="text/javascript">
$(function(){
var $cat = $("#state"),
$subcat = $(".subcat");
$cat.on("change",function(){
var _rel = $(this).val();
$subcat.find("option").attr("style","");
$subcat.val("");
if(!_rel) return $subcat.prop("disabled",true);
$subcat.find("[rel="+_rel+"]").show();
$subcat.prop("disabled",false);
});
});
</script>
</body>
</html>