首页 > 解决方案 > 顶部菜单显示一个空白选项,将我重定向到未定义的页面。我该如何解决?

问题描述

我有一个有一些问题的博客网站。当您尝试在智能手机中打开我的博客或将其放大到 300% 时,您会看到顶部菜单变成了一个下拉菜单,其中第二个位置有一个空白选项。当任何人单击它时,它会重定向到 404 错误页面。请帮我解决这个错误。

我附上一些图片以供参考。

屏幕截图显示没有空白选项的菜单

显示带有空白选项的菜单的屏幕截图

显示 404 错误页面的屏幕截图

我还将使用它添加菜单条码。

// 插件:SelectNav.js ~ url: https://github.com/lukaszfiszer/selectnav.js window.selectnav=function(){"use strict";var e=function(e,t){function c(e ){var t;if(!e)e=window.event;if(e.target)t=e.target;else if(e.srcElement)t=e.srcElement;if(t.nodeType===3 )t=t.parentNode;if(t.value)window.location.href=t.value}function h(e){var t=e.nodeName.toLowerCase();return t==="ul"|| t==="ol"}函数 p(e){for(var t=1;document.getElementById("selectnav"+t);t++);return e?"selectnav"+t:"selectnav"+(t -1)}函数d(e){a++;var t=e.children.length,n="",l="",c=a-1;if(!t){return}if(c){ while(c--){l+=o}l+=" "}for(var v=0;v"+l+g+"";if(s){var b=e.children[v].children 1;if(b&&h(b)){n+=d(b)}}}}if(a===1&&u){n=''+u+""+n}if(a===1){n= ''+n+""}a--;return n}e=document.getElementById(e);if(!e){return}if(!h(e)){return}if(!("insertAdjacentHTML"in window.document.documentElement)){return}document.documentElement.className+="js";var n=t||{},r=n.activeclass||"active",i=typeof n.autoselect===" boolean"?n.autoselect:true,s=typeof n.nested==="boolean"?n.nested:true,o=n.indent||"-",u=n.label||"Menu", a=0,f="已选择";e.insertAdjacentHTML("afterend",d(e));var l=document.getElementById(p());if(l.addEventListener){l.addEventListener("change" ,c)}if(l.attachEvent){l.attachEvent("onchange",c)}return l};return function(t,n){e(t,n)}}();

标签: javascriptphphtmlcss

解决方案


您可以将此脚本添加到您的网站。我用 chrome 调试工具进行了测试,它工作正常。

当您调整浏览器大小或在 ipad/iphone 中使用时,它将触发代码删除未定义的选项

$(window).resize(function(){
    if ($(window).width()< 992){
      $('.selectnav option').each(function(index,item){ 
        if($(item).val() == "undefined"){ $(this).remove();}
      });
    }
});

推荐阅读