来自select选项的Javascript / Jquery-切换类别和子类

时间:2012-05-24 06:27:46

标签: javascript jquery javascript-events

我正在尝试在类别中切换选择选项。我正在使用java脚本树函数从我的类别和子类别中进行选择。我无法让它发挥作用。逻辑似乎很清楚,但也许代码不遵循它。这是我的代码:

<script type="text/javascript">
$(document).ready(function() {
    var displayParents = function() {
        var lastitem = "";
        $(this).siblings('select') // find all select
            .find(':selected') // and their current options
            .each(function() {
                lastitem = $(this).text();
            }); // and add option text to array
        allowToContinue(lastitem);
    }
    var option_tree = {"0":{"books":"Books &gt; ","electronics":"Electronics &gt; ","furniture":"Furniture &gt; ","clothing":"Clothing &gt; ","jobs-services":"Jobs/Services &gt; ","housing":"Housing &gt; "},"books":{"books-textbooks":"Textbooks ","books-other-books":"Other Books "},"electronics":{"electronics-computers":"Computers &gt; ","electronics-audio-video-photos":"Audio \/ Video \/ Photos &gt; ","electronics-cellphones":"Cellphones &gt; ","electronics-others":"Others"},"electronics-computers":{"electronics-computers-accesories":"Accessories","electronics-computers-pc":"PC","electronics-computers-mac":"Apple"},"electronics-audio-video-photos":{"electronics-audio-video-photos-mp3-ipod-speakers":"MP3 \/ IPOD \/ Speakers","electronics-audio-video-photos-tv-dvd-cameras":"TV \/ DVD \/ Cameras","electronics-audio-video-photos-video-games":"Video Games","electronics-audio-video-photos-others":"Others"},"electronics-cellphones":{"electronics-cellphones-accessories":"Accesories","electronics-cellphones-others":"Others"},"housing":{"housing-apartments":"Apartments","housing-houses":"Houses &gt ","housing-roommates":"Roommates","housing-dorms":"Dorms &gt "},"housing-dorms":{"housing-dorms-dunn":"Dunn","housing-dorms-martin":"Martin","housing-dorms-morrison":"Morrison","housing-dorms-myers":"Myers","housing-dorms-rice":"Rice","housing-dorms-smith":"Smith"},"housing-houses":{"housing-houses-rent":"Rent"},"housing-roommates":{"housing-roommates-looking":"Looking for Roommate"},"housing-apartments":{"housing-apartments-off-campus":"Off Campus","housing-apartments-campus":"Campus &gt; "},"housing-apartments-Campus":{"housing-apartments-campus-fair-commons":"Fair Commons","housing-apartments-campus-south-campus":"South Campus","housing-apartments-campus-tara-east":"Tara East","housing-apartments-campus-mansfield":"Mansfield"},"jobs-services":{"jobs-services-jobs":"Jobs","jobs-services-tutoring-lessons":"Tutoring \/ Lessons","jobs-services-events-seminars":"Events \/ Seminars \/ Presentations ","jobs-services-haircuts":"Haircuts","jobs-services-others":"Others"},"furniture":{"furniture-beds":"Beds","furniture-couches-chairs-futons":"Couches \/ Chairs \/ Futons \/ etc","furniture-tables-desks":"Tables \/ Desks","furniture-others":"Others"},"clothing":{"clothing-men":"Men","clothing-women":"Women"}};
    var options = {
        set_value_on: 'each',
        show_multiple: 11,
        choose: '',
        indexed: true,
        select_class: 'selectCategory'
    };
    $('#category-select').optionTree(option_tree[0], options).change(displayParents);
}); 
</script> 

0 个答案:

没有答案