我是新手,刚刚修改带有选项列表的可过滤投资组合,下面是我修改后的 jquery 代码。从 li 项到选项选择。
我收到来自 firebug 的语法错误。那么我哪里做错了?
错误:语法错误,无法识别的表达式:选项[数据类型~=otw-twentyfour otw-columns] ....value:null},fb.error=function(a){抛出 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++;
}
}
?>
最佳答案
$portfolioClone.find("option[data-type~='" + $filterClass + "']");
在 $filterClass 周围添加了单引号
关于javascript - 将 Jquery 可过滤组合转换为选项选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27411713/