javascript - onMouseOver、超链接和 rel...帮助我 :(

标签 javascript html dom-events

目前,我在 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/

相关文章:

javascript - 对对象数组进行排序的简单函数

javascript - 如何在 d3.js 中显示一年时间刻度上的最小日刻度

javascript - 如何计算所有嵌套对象的相同值的计数?

HTML5 视频标签访问进度事件属性已加载和总计

javascript - 如何在页面加载后立即使用自动启动参数暂停 Brightcove 视频?

javascript - Less 中的变量操作

javascript - 轨道 3 jQuery : How to alert id of td

javascript - 如何在 2 个 <div> 之间使用 html Canvas

html - 如何在 Font Awesome 图标中使用渐变?

javascript - 如何设置位置