我想在nav元素<a>
上添加EventListioner,但它不起作用。我不喜欢通过jQuery来解决它。我的代码如下:
<div id="navigation">
<nav class="navbg clearfix">
<a class="navcell" href="#">item1</a>
<a class="navcell" href="#">item2</a>
<a class="navcell" href="#">item3</a>
<a class="navcell" href="#">item4</a>
<a class="navcell" href="#">item5</a>
<a class="navcell" href="#">item6</a>
</nav>
</div>
JS是:
<script type="text/javascript">
var navobj = document.getElementById("navigation").getElementsByTagName("a");
for(var i=0; i < navobj.length; i++){
navobj[i].onmouseover = function(){
DD_belatedPNG.fix('.selected');
}
</script>
答案 0 :(得分:0)
您的功能未正确关闭,您缺少一个'}'
<script type="text/javascript">
var navobj = document.getElementById("navigation").getElementsByTagName("a");
for(var i=0; i < navobj.length; i++){
navobj[i].onmouseover = function(){
DD_belatedPNG.fix('.selected');
};
}
</script>
答案 1 :(得分:0)
使用这个JS:
<script type="text/javascript">
var navobj = document.getElementById("navigation").getElementsByTagName("a");
for(var i=0; i < navobj.length; i++){
navobj[i].onmouseover = function(){
DD_belatedPNG.fix('.selected');
} //you have missed this closing bracket.
}
</script>
你错过了一个结束的大括号。