将Jquery可过滤的投资组合转换为期权选择

时间:2014-12-10 22:04:48

标签: javascript php jquery

我是新手,只修改带有选项列表的可过滤投资组合,下面是我修改过的jquery代码。从li项目到选项选择。

我从firebug收到语法错误。那我在哪里做错了?

错误:语法错误,无法识别的表达式:选项[data-type~ = otw-twentyfour otw-columns] .... value:null},fb.error = function(a){throw new Error("语法错误,无法识别ex ...

jQuery('select').on('change', function (e) {

    jQuery(".otw-portfolio-filter option").removeClass("current");


    // Get the class attribute value of the clicked link

    var $filterClass = jQuery(this).parent().attr("class");


    if ( $filterClass == "all" ) {

        var $filteredPortfolio = $portfolioClone.find("option");

    } else {

        var $filteredPortfolio = $portfolioClone.find("option[data-type~=" + $filterClass + "]");

    }

    // Call quicksand

    jQuery("ul.otw-portfolio").quicksand( $filteredPortfolio, {

        duration: 500,

        easing: 'easeInOutQuad'

    });


    jQuery(this).parent().addClass("current");

    // Prevent the browser jump to the link anchor

    e.preventDefault();

})

PHP代码

<?php $taxo = get_object_taxonomies( 'otw-portfolio' );
                foreach ( $taxo as $tax_name ) {
                    $categories = get_categories('taxonomy='.$tax_name);
                    $i = 0; $len = count( $categories );
                    foreach ($categories as $category) {
                        if ($i == 0) { ?><select name="select" id="select" class="otw-portfolio-filter"> <option value="#" class="all" style="float:right;"><?php _e( 'All', 'otw_pfl' ); ?></option><?php }
                            echo '<option value="#" class="'.$category->category_nicename.'">'.$category->cat_name.'</option>';
                        if ($i == $len - 1) { echo '</select>'; }
                        $i++;
                    }
                }
              ?>

2 个答案:

答案 0 :(得分:2)

$portfolioClone.find("option[data-type~='" + $filterClass + "']");

在$ filterClass

附近添加了单引号

答案 1 :(得分:0)

我的最后一次尝试;)

var $portfolioClone = jQuery(".otw-portfolio").clone();
jQuery('select').on('change', function (e) {
    var $filterClass = jQuery("option:selected", "select").attr("class");

    if ( $filterClass == "all" ) {

            var $filteredPortfolio = $portfolioClone.find("li");

        } else {

            var $filteredPortfolio = $portfolioClone.find("li[data-type~=" + $filterClass + "]");

        }



        // Call quicksand

        jQuery("ul.otw-portfolio").quicksand( $filteredPortfolio, {

            duration: 500,

            easing: 'easeInOutQuad'

        });

    // Prevent the browser jump to the link anchor
    e.preventDefault();
})