0

これが私が取り組んでいるサイトです:http://cirkut.net/sub/northwood/popunder/

基本的に私がやろうとしているのは、ドロップダウンにカーソルを合わせた後、側面にある4つのリンクをクリックすると、選択した内容に基づいてコンテンツが変更されます。私のフィルタリングは初期ロードで機能しますが、クリックした後、たとえばLocations、中央と右のコンテンツ列に何も伝播しません。

これまでのキーアップのコードは次のとおりです。

$('.megaMenu .menuSearchBar').on("keyup",function(event){
            //NONE OF THIS FIRES AFTER SELECTING a MENU ITEM
            var activeitem = $('.leftmenu a.active').text();
            activeitem = activeitem.toLowerCase();
            activeitem = activeitem.split(' ').join('-');

            data = null;
            //Switch to determine which data to use during filtering
            switch(activeitem){
                case 'programs':
                    data = programs;
                    break;
                case 'locations':
                    data = locations;
                    break;
                case 'financial-aid':
                    data = financialaid;
                    break;
                case 'admissions':
                    data = admissions;
                    break;
            }
            var typedtext = $(this).val();
            var matching = new Array();
            for(index in data){
                for(i in data[index]){
                    if(data[index][i].toLowerCase().indexOf(typedtext.toLowerCase()) != -1){
                        matching.push(data[index][0]);
                        break;
                    }
                }
            }
            //Filtering code goes here, just know that it outputs
            //into the middle and right columns
});
$('.megaMenu .menuSearchBar').keyup(); //Propagate initial content in middle and left column

アイテムを切り替えるために<div>、メニューアイテムをクリックするとすべてが変わる4つの検索列(左側のコンテンツ)を保持する非表示があります。メニュー項目がクリックされたときのコードは次のとおりです。

$('.leftmenu a').click(function(){
    var oldactive = active;
    $('.leftmenu a').removeClass('active');
    $(this).addClass('active');
    //Get the new active item and set it so it can be compared in the switch above
    var active = $('.leftmenu').find('.active').text();
    active = active.toLowerCase();
    active = active.split(' ').join('-');
    //Change the left content to the search bar correlating to item clicked 
    $('.superNav .left').html($('.hidden .'+active).html());
    //Clear out the middle and right content for new data
    $('.middle').html('');
    $('.right').html('');
    //Supposed to trigger the above .on() call to set the new content, but doesn't.
    $('.megaMenu .menuSearchBar').keyup();
});

サイドメニュー項目をクリックしなくても、on keyup機能は完全に機能します。

関数が正しく起動しなくなったため、私の問題はleftクリックの範囲内にあるはずです。keyup

何か案は?

4

2 に答える 2

1

.on操作されたComで作業するために使用している場合は、.on間違った方法を使用しています

$('body').on("keyup",.megaMenu .menuSearchBar,function(event){//first line should be like this

正しい構文は次のとおりです

$("parent element").on(event,children element,function)

イベントを親要素にバインドしますが、子要素でイベントが発生した場合にのみトリガーされます

于 2012-06-11T16:12:51.083 に答える
1

これ

$('.megaMenu .menuSearchBar').on("keyup",function(event){ 

する必要があります

$('body').on("keyup",'.megaMenu .menuSearchBar',function(event){

bodyを、選択した要素の任意の親要素に置き換えることができます。

于 2012-06-11T16:14:39.663 に答える