次のコードでは、ページの開始時と選択時の2つのドロップダウンメニューを変更しています。最初のものは、ページのカテゴリに適応すべき主なカテゴリを含んでいます。次に、最初のもので選択されたもの(ページ開始または選択のいずれか)に応じて、2番目のオプションが異なるオプションを提供します。Firefoxで予期したとおりにドロップダウンが変更されない
次のコードは最新の主要なブラウザでは正常に動作しますが、Firefoxでは想定されていません。
私のpageCatオプションの最初のドロップダウンで、イエスがトップに移動しますが、それでもFirefoxでは古いテキストが可視フィールドに保持されるという問題が発生します。ここで意味的な問題がありますか?
jQuery(document).ready(function(){
// get the page category
var pageCat = jQuery("#page-wrapper .breadcrumb").find("li.active").text().replace(/\s+/g, '-').toLowerCase();
// get inserted post category instead in case of single seminar
if (jQuery(".courses-detail").length) {
jQuery('.courses-detail').each(function() {
$courseCat = this.className.match(/(^|\s)sw_course_cat\S+(\s|$)/);
});
pageCat = $courseCat[0].replace('sw_course_cat-','').trim();
};
// store drop down menus
var $dropDown = jQuery('#page-wrapper select[name="courses[category]"]');
var $dropDown_2 = jQuery('#page-wrapper select[name="courses[location]"]');
// make it the first in the drop down list
// remove “all categories” option
var $standard = $dropDown.find('option[data-link="http://www.falkenberg-seminare.de/cms/edu-course/"]');
$standard.remove();
// change position
var $startList = $dropDown.find('option[value="' + pageCat + '"]');
$startList
.remove();
$dropDown.prepend($startList);
// filter the second drop down based on first drop down option selected
var $options = $dropDown_2.clone(); // this will save all initial options in the second dropdown
$dropDown.change(function() {
var filters = [];
if (jQuery(this).val() == "") {
jQuery(this).find("option").each(function(index, option) {
if (jQuery(option).val() != "")
filters.push(jQuery(option).val());
});
} else {
filters.push(jQuery(this).val())
}
$dropDown_2.html("");
jQuery.each(filters, function(index, value) {
$options.find("option").each(function(optionIndex, option) { // a second loop that check if the option value starts with the filter value
if (jQuery(option).val().startsWith(value))
jQuery(option).clone().appendTo($dropDown_2);
});
});
});
$dropDown.trigger('change');
});
私はフィドルを提供しないために申し訳ありませんが、私は、ページの読み込みに正しく実証するpageCat選択をエミュレートする方法を想像することはできません。しかし、私が知らないFirefoxコードの問題があるかもしれません(そして、Googleは助けませんでした)。
ありがとうございました!私のコードの拡張