引入iframe, 头部跳转并点亮效果


<script> /** * @Author: zhangcs * @Date: 2018-09-20 * @cnblogs: https://www.cnblogs.com/zhangchs */ var pathname = window.parent.location.pathname; // 获取父窗口的路径字符串 var a = document.getElementById('nav').getElementsByTagName('a'); //找到超链接a元素 for ( var i = 0; i < a.length; i++ ) { // 获取超链接:【./名称.html】 中的 '名称' var param = a[i].getAttribute('href').substring(2, a[i].getAttribute('href').length - 5); //console.log(param); if ( pathname.indexOf(param) != -1 && a[i].getAttribute('href') != '' ) { a[i].className = 'active'; } else { a[i].className = ''; } } //需要引入jquery /*$("#nav a").each(function () { var param = $(this).attr('href').substring(2, $(this).attr('href').length-5); if ( ( pathname.indexOf(param) != -1 || false ) && $(this).attr('href')!= '' ) { $(this).addClass('active'); valid = true; } else { $(this).removeClass('active'); } });*/ </script>

思想:用父窗口和子窗口的url做比较,子窗口中的超链接 和 父窗口中的url的路径名比较

原文地址:https://www.cnblogs.com/zhangchs/p/9682642.html