目前,我在 JavaScript 上有一个轮播,当我们点击超链接时它会工作,如下所示:
<div id="direction1">
<p>
<a href="javascript:" class="carousel-control" rel="next"><img class="fleche_suiv" src="/project/images/next.png" alt="Suivant" title="Suivant" />
</a>
</p>
</div>
我也想用 onMouseOver
来执行这个事件。
所以我尝试了这个,但它不起作用:
<div id="direction1">
<p onMouseOver="this.getElementsByTagName('a').click()">
<a href="javascript:" class="carousel-control" rel="next"><img class="fleche_suiv" src="/project/images/next.png" alt="Suivant" title="Suivant" />
</a>
</p>
</div>
如何解决?
附言:
这是有问题的 JS 代码:
next: function () {
if (this.current) {
var currentIndex = this.current._index;
var nextIndex = (this.slides.length - 1 == currentIndex) ? (this.options.circular ? 0 : currentIndex) : currentIndex + 1;
} else {
var nextIndex = 1;
}
if (nextIndex == 0 && this.options.circular && this.options.effect != 'fade') {
this.scroller.scrollLeft = 0;
this.scroller.scrollTop = 0;
nextIndex = 1;
}
if (nextIndex > this.slides.length - (this.options.visibleSlides + 1)) {
nextIndex = this.slides.length - this.options.visibleSlides;
}
this.moveTo(this.slides[nextIndex]);
}
最佳答案
click
事件在您的代码中的哪个位置分配给 anchor 元素?此外,为什么要单独使用单独的元素来分配 mouseover
事件?
你可以更好的使用
<div id="direction1">
<a href="http://linktothepicture" onmouseover="yourObject.next()" class="carousel-control" rel="next"><img class="fleche_suiv" src="/project/images/next.png" alt="Suivant" title="Suivant" /></a>
</div>
或者更好地将 JavaScript 分配到一个单独的文件中:
window.onload = function () {
var nextButton = document.getElementById("idOfNextButton");
nextButton.onmouseover = yourObject.next;
};
这样,当用户没有启用 JavaScript 和/或在下一步按钮上单击鼠标中键时,您的网站仍然可以正常运行。
关于javascript - onMouseOver、超链接和 rel...帮助我 :(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2942315/