我是新手,只是使用选项列表修改可过滤的投资组合,下面是我修改的jquery代码。 从 li 项到选项选择。
我收到来自萤火虫的语法错误。那么我哪里做错了?
错误:语法错误,无法识别的表达式:选项[数据类型~=otw-二十四个 otw 列]....value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized 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++;
}
}
?>
$portfolioClone.find("option[data-type~='" + $filterClass + "']");
在$filterClass两边添加了单引号
我最后一次尝试;)
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();
})