jQuery绑定在Firefox中不起作用

jQuery绑定在Firefox中不起作用

本文介绍了jQuery绑定在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将click事件与jquery绑定时遇到问题.在所有浏览器中都可以正常工作,但在Firefox中却不能.预先感谢您的回答.

I've a problem binding a click event with jquery. It's working fine in all browsers but not in Firefox. Thanks in advance for your answer.

var conf_markers = function() {

        // create a wrapper for our markers
        $m_wrapper = $('<ol class="bjqs-markers"></ol>');

        // for every slide, create a marker
        $.each($slides, function(key, slide){

            var slidenum    = key + 1,
                gotoslide   = key + 1;

            if(settings.animtype === 'slide'){
                // + 2 to account for clones
                gotoslide = key + 2;
            }

            var marker = $('<li><a href="#"></a></li>');

            // set the first marker to be active
            if(slidenum === state.currentslide){ marker.addClass('active-marker'); }

            // bind the click event
            marker.bind('click','a',function(e){
                e.preventDefault();
                if(!state.animating && state.currentslide !== gotoslide){
                    go(false,gotoslide);
                }
            });

            // add the marker to the wrapper
            marker.appendTo($m_wrapper);

        });

        $m_wrapper.appendTo($wrapper);
        $m_markers = $m_wrapper.find('li');

        // center the markers
        if (settings.centermarkers) {
            $m_wrapper.addClass('h-centered');
            var offset = (settings.width - $m_wrapper.width()) / 2;
            $m_wrapper.css('left', offset);
        }

    };

据我所知,line marker.bind('click','a',function(e){是导致这种情况的那个.

The line marker.bind('click','a',function(e){ is the one causing this for as far as I can see.

推荐答案

尝试替换该行

marker.bind('click','a',function(e){

与此

// New way (jQuery 1.7+) - .on(events, selector, handler)
marker.on('click', 'a', function(e){

由于链接是动态添加的,因此您需要使用事件委托使用 on()注册事件处理程序. .

Since, the links are added dynamically, you need to use event delegation to register the event handler using on().

这篇关于jQuery绑定在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:44