[英]JQuery onclick code doesn't work
Welcome, I have this code: html: 欢迎使用,我有以下代码:html:
<script src="loginbox.js"></script>
<div class="menu" id="login">
<p class="menu">LOG IN</p>
</div>
js: js:
$('#login').on('click', function(){
document.getElementById('login').hide();
});
The div "login" isn't even clickable div“登录”甚至不可点击
Here you go : 干得好 :
$(document).ready(function(){
$('#login').on('click', function(){
$(document.getElementById('login')).hide();
});
});
When you mix pure JS and jQuery, you need to wrap pure JS in a jQueryObject. 当您混合使用纯JS和jQuery时,需要将纯JS包装在jQueryObject中。
PS: I'd swap the $(document.getElementById('login'))
for a $("#login")
if I were you PS:如果我是我,我会将
$(document.getElementById('login'))
换成$("#login")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.