我正在使用OSClass构建一个将持有多个分类广告的网站。不幸的是,有些脚本与Firefox / IE不兼容,所以我需要跟踪这些错误。
脚本应该是这样的:
这是.js文件:
var is_loading = true ;
function fill_subcategory_select ( id ) {
var category = $("select.category") ;
var subcategory = $("select.subcategory") ;
// reset subcategory select
subcategory.html("") ;
console.log(twitter_theme.categories["id_" + id]) ;
// check that the category has subcategories
if( typeof twitter_theme.categories["id_" + id] === "undefined" ) {
console.log("[fill_subcategory_select] hide subcategory") ;
subcategory.append( $("<option>").attr('value', id) ) ;
subcategory.css("display", "none") ;
$("select.subcategory").trigger('change') ;
return true;
}
subcategory.html()
subcategory.append( $("<option>").attr('value', id).html(twitter_theme.text_select_subcategory) ) ;
$.each(twitter_theme.categories["id_" + id], function(key, value) {
console.log("[fill_subcategory_select] subcategory { id: " + value.id + ", slug: " + value.slug + ", name: " + value.name + " }") ;
subcategory.append( $("<option>").attr('value', value.id).html(value.name) ) ;
}) ;
subcategory.css("display", "") ;
return true;
}
以下是实际形式:
<script type="text/javascript">
twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter_bootstrap') ; ?>" ;
twitter_theme.category_selected_id = "<?php echo item_selected_category_id() ; ?>" ;
twitter_theme.subcategory_selected_id = "<?php echo item_selected_subcategory_id() ; ?>" ;
</script>
<!-- category input -->
<div class="clearfix">
<label><?php _e('Category', 'twitter_bootstrap') ; ?></label>
<div class="input">
<?php item_category_select( __('Select a category', 'twitter_bootstrap') ) ; ?>
</div>
</div>
<!-- category input end -->
Firefox中发生的情况是,当您选择一个类别时,子类别列表根本不会显示,这会破坏注册表单的功能,因为它会显示错误消息:“无效的类别”。
答案 0 :(得分:2)
最后,我发现了问题。问题出在item_category_select_js()
函数中。您可以在./twitter_bootstrap/functions.php
中找到此功能。这是新代码:
function item_category_select_js() {
?>
<script type="text/javascript">
twitter_theme.categories = {} ;
<?php
$aCategories = osc_get_categories() ;
foreach($aCategories as $category) {
if( is_array($category['categories']) && (count($category['categories']) > 0) ) {
echo 'twitter_theme.categories.id_' . $category['pk_i_id'] . ' = {' . PHP_EOL ;
for($i = 0; $i < count($category['categories']); $i++) {
echo $category['categories'][$i]['pk_i_id'] . ': { id: ' . $category['categories'][$i]['pk_i_id'] . ', slug: "' . addslashes($category['categories'][$i]['s_slug']) . '", name: "' . addslashes($category['categories'][$i]['s_name']) . '"' ;
if( $i == (count($category['categories']) - 1) ) {
echo '}' . PHP_EOL ;
} else {
echo '} ,' . PHP_EOL ;
}
}
echo '} ;' ;
} else {
echo 'twitter_theme.categories.' . $category['s_slug'] . ' = { } ;' . PHP_EOL ;
}
}
?>
</script>
<?php
}
它已在上一版本(1.2.1)中修复。您可以从这里下载:https://sourceforge.net/projects/osclass/files/Themes/twitter/