我在wordpress网站上有这个js代码,它只在firefox上有效,在其他浏览器上不起作用。此代码应将每个容器(称为type的每个容器)的元素排序为a-z。我试着用js编写,但可能会被chrome接受,但它没有对每个容器中的元素进行排序。我该怎么办??另外,我正在使用“页脚和页眉脚本”插件来编写代码,但稍后将在一个单独的主题中完成
<!--: this script sorts the table of all programs from A-Z -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$('document').ready(function() {
var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());
//all types
var programs = ["zuschuesstypeID","darlehnTypeID","buergschaftTypeID","grantienTypeID"];
sortAllTypes (programs);
removeBrowserError(is_chrome); //remove scroll error on Chrom
});
//sort AllTypes
function sortAllTypes (programs) {
for (let i = 0; i < programs.length; i++) {
sortTypeContainer(programs[i]);
}
}
//sort for works only for Firefox
function sortTypeContainer(containerName) {
var $TypeElements = $(`#${containerName} .col-lg-12`);
var sortedType = $TypeElements.sort(function(a, b) {
return $(a).find("h4").text() > $(b).find("h4").text();
});
//rewrite Type in the table
$(`#${containerName} .row`).html(sortedType);
}
//remove scrolling error from chrome
function removeBrowserError(is_chrome) {
if (is_chrome) {
//remove erro
window.addEventListener('wheel', { passive: false });
}
}
</script>
暂无答案!
目前还没有任何答案,快来回答吧!