我无法在移动浏览器(Safari)中使用此下拉列表我可以知道是什么问题?它在桌面浏览器中运行良好,如Chrome,Safari ..此代码由Adobe Muse生成。
我也在iPhone6 Plus中试过这段代码。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body {
font-family: 'Asap', sans-serif;
color: #7F7F7F;
}
/* Dropdown style */
.dropdown {
margin: 0 auto;
margin-bottom: 1em;
}
.dropdown dt a {
display: block;
height: 2.5em;
width: 298px;
border: 1px solid #ecf0f1;
border-radius: 3px;
text-decoration: none;
}
.dropdown dt a:hover, .dropdown dt a:active {
border-color: #eeeeee;
}
.dropdown dt span {
display: block;
padding: 0 1em;
line-height: 2.5em;
border-right: 1em solid transparent;
cursor: pointer;
}
.dropdown dd {
position: relative;
}
.dropdown dd ul {
display: none;
position: absolute;
left: -40px;
top: -1.0em;
width: 298px;
list-style: none;
background: #fff none repeat scroll 0 0;
border: 1px solid #bdc3c7;
border-radius: 3px;
}
.dropdown dd ul li:first-child a:hover {
border-radius: 3px 3px 0 0;
}
.dropdown dd ul li:last-child a:hover {
border-radius: 0 0 3px 3px;
}
.dropdown dd li a {
display: block;
line-height: 2.5em;
text-decoration: none;
}
.dropdown dd li a:hover {
background-color: #F6F6F6;
color: #7F7F7F;
cursor: pointer;
}
.selected {
font-weight: 700;
}
</style>
</head>
<body>
<dl class="dropdown">
<dt><a><span>What's your budget?</span></a></dt>
<dd>
<ul>
<li><a>I'll mention my budget below</a></li>
<li><a>I don't know my budget yet</a></li>
<li><a>I'd rather not share my budget</a></li>
</ul>
</dd>
</dl>
<script type="text/javascript">
var dropdowns = $(".dropdown");
// Onclick on a dropdown, toggle visibility
dropdowns.find("dt").click(function(){
dropdowns.find("dd ul").hide();
$(this).next().children().toggle();
});
// Clic handler for dropdown
dropdowns.find("dd ul li a").click(function(){
var leSpan = $(this).parents(".dropdown").find("dt a span");
// Remove selected class
$(this).parents(".dropdown").find('dd a').each(function(){
$(this).removeClass('selected');
});
// Update selected value
leSpan.html($(this).html());
// If back to default, remove selected class else addclass on right element
if($(this).hasClass('default')){
leSpan.removeClass('selected')
}
else{
leSpan.addClass('selected');
$(this).addClass('selected');
}
// Close dropdown
$(this).parents("ul").hide();
});
// Close all dropdown onclick on another element
$(document).bind('click', function(e){
if (! $(e.target).parents().hasClass("dropdown")) $(".dropdown dd ul").hide();
});
</script>
</body>
</html>
答案 0 :(得分:0)
您是否在代码中添加了jQuery库?
尝试在特定脚本标记之前添加它。
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
var dropdowns = $(".dropdown");
等...