【发布时间】:2016-05-04 21:26:04
【问题描述】:
我正在使用 onclick 功能在我的移动网站上下拉一个简单的列表,但它不起作用 - 代码如下。奇怪的是,我旁边还有其他格式完全相同的东西,而且效果很好(当然,所有的名字都不同)。
显然“show3”类没有被切换,因为我可以更改“display: none;”在 .incoming-listc 中“显示:阻止”,它显示得很好。但是,当我点击“传入”跨度时,什么也没有发生!
HTML:
<div class="mobile-incoming">
<span onclick="myFunction3()">Incoming <i class="fa fa-angle-down"></i></span>
<div id="incoming-list" class="incoming-listc">
Updated 5.4.16<br>Goodall RCJ EIR/Adirondack<br>2008 Martin 000-18 Authentic
</div>
</div>
<script>
function myFunction3() {
document.getElementById("incoming-list").classList.toggle("show3");
}
</script>
CSS:
.mobile-incoming {
position: fixed;
top: 0;
right: 60px;
cursor: pointer;
text-align: right;
line-height: 44px;
font-family: "Helvetica Neue", Verdana;
font-size: 0.8em;
font-weight: 200;
color: white;
}
.incoming-listc {
display: none;
position: fixed;
top: 45px;
right: 0;
left: 0;
background: rgba(70, 70, 70, 0.9);
border-bottom: 1px solid white;
}
.show3 {
display: block;
}
【问题讨论】:
-
.toggle()是一个 jQuery 函数。这里加载了 jQuery 吗? -
即使加载了 jQuery,它也不会工作,因为切换不是在 jQuery 元素上执行的。
-
但不是jQuery函数:w3schools.com/jsref/prop_element_classlist.asp
-
也许你正在 IE 上测试它。 IE不支持
-
我刚刚试了一下,它可以工作,也许你使用的是 Asaf 建议的旧浏览器。
标签: javascript html css