It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                已关闭8年。
            
        

我需要将此on函数重写为click函数。具有完全相同的功能
我不能使用,因为我必须使用jQuery 1.3

$('#citybreak_availability_calendar_widget').on('click', '#CB_SearchButton', function() {
    var iframe = $('#citybreakContent').find('iframe');
    iframe.attr('src', $(this).attr('href'));
    $('#menu ul li a[title="Boka rum"]').click();
    return false;
});


这就是我得到的:

$('#citybreak_availability_calendar_widget #CB_SearchButton').click(function() {
    var iframe = $('#citybreakContent').find('iframe');
    iframe.attr('src', $('#CB_SearchButton').attr('href'));
    $('#menu ul li a[title="Boka rum"]').click();
    return false;
});

最佳答案

这里:

$( '#citybreak_availability_calendar_widget' ).click( function ( e ) {
    if ( e.target.id === 'CB_SearchButton' ) {
        // your code
    }
});


由于您使用的1.3版本不提供现成的事件委托功能,因此您必须手动实现它。这个想法是将点击处理程序绑定到wrapper元素,然后-在处理程序内部-手动检查事件目标-e.target属性-是否是正确的元素。

关于javascript - 将jQuery on()重写为click(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9516182/

10-13 04:45