[英]jQuery and HTML5 tags?
I am currently developing a HTML5 page, so I want to use jQuery for some effects. 我目前正在开发HTML5页面,因此我想使用jQuery产生一些效果。 Here's my code that doesn't seem to work: 这是我的似乎无效的代码:
The html code: html代码:
<nav id="mainNavigation">
<!--....-->
</nav>
and now jQuery: 现在是jQuery:
$('#mainNavigation').click(function(){
alert("test");
});
For some reason, nothing is happening. 由于某种原因,什么也没有发生。 When I try something like: 当我尝试类似的东西:
$(document).ready(function(){
alert("test");
})
everything works fine. 一切正常。
Thank you for any help. 感谢您的任何帮助。
It sounds like you aren't wrapping your code in a document ready. 听起来您没有将代码包装在准备好的文档中。 This is basically telling the code to run with the DOM is ready. 这基本上是在告诉要与DOM一起运行的代码已准备就绪。
Are you doing this: 您在这样做吗?
$(document).ready(function() {
$('#mainNavigation').click(function(){
alert("test");
});
});
As per motoxer4533's comment you can also do this via jQuery's shorthand Document ready: 根据motoxer4533的注释,您还可以通过jQuery的速记文档准备好此操作:
$(function() {
$('#mainNavigation').click(function(){
alert("test");
});
});
Try with: 尝试:
$(document).ready(function(){
$('#mainNavigation').click(function(){
alert("test");
});
})
or 要么
$(document).ready(function(){
$('#mainNavigation').live('click', function(){
alert("test");
});
})
$(document).ready(function(){
$('#mainNavigation').live('click', function(){
alert("test");
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.