(function(){ var map = { 'index' : 0, 'gift_code' : 1, 'base_info' : 1, 'band_phone': 1, 'unlink_phone': 1, } function isSelect(idx){ var pathname = location.pathname; pathname = pathname.split('/')[2]; return map[pathname] != idx ? ' <li>' : ' <li class="selected">' } document.write('<div class="menus">'); document.write(' <ul class="menu_ul">'); document.write(isSelect(0)); document.write(' <a href="/xycenter/index/" class="su_nav">首页</a>'); document.write(' </li>'); document.write(' <li>'); document.write(' <a href="/safecenter/index/" class="su_nav has_sub" target="_blank">安全中心<i></i></a>'); document.write(' <div class="sub_menu">'); document.write(' <a href="/safecenter/lock_index/" class="sub_nav">安全锁定</a>'); document.write(' <a href="/safecenter/change_pwd_by_phone/" class="sub_nav">密码管理</a>'); document.write(' <a href="/safecenter/safe_fdmj/" class="sub_nav">防盗秘籍</a>'); document.write(' </div>'); document.write(' </li>'); document.write(' <li>'); document.write(' <a href="/callcenter/index/" class="su_nav has_sub" target="_blank">客服中心<i></i></a>'); document.write(' <div class="sub_menu">'); document.write(' <a href="/callcenter/self_help/" class="sub_nav" target="_self">自助服务</a>'); document.write(' <a href="/callcenter/helps/" class="sub_nav">帮助</a>'); document.write(' </div>'); document.write(' </li>'); document.write(isSelect(1)); document.write(' <a href="/usercenter/gift_code/" class="su_nav">我的帐户</a>'); document.write(' </li>'); document.write(' </ul>'); document.write('</div>'); document.write('<a href="javascript:;" class="su_logo">'); document.write(' <img style="width:250px;"src="abc.png" />'); document.write('</a>'); })();
另一种方式:
(function(){ document.write('<div class="links" id="uc_links">'); document.write(' <div class="link">'); document.write(' <a href=""><i></i><span>基本资料</span></a>'); document.write(' </div>'); document.write(' <div class="link">'); document.write(' <a href=""><i></i><span>礼包码</span></a>'); document.write(' </div>'); document.write(' <div class="link">'); document.write(' <a href=""><i></i><span>手机绑定</span></a>'); document.write(' </div>'); document.write(' <div class="link">'); document.write(' <a href=""><i></i><span>手机解绑</span></a>'); document.write(' </div>'); document.write('</div>'); var pathname = location.pathname; pathname = pathname.split('/')[2]; var linksCon = document.getElementById('uc_links'); var links = linksCon.getElementsByTagName('a') , len = links.length; if(pathname){ var sub; for(var i=0;i<len;i++){ if(links[i].getAttribute('href').indexOf(pathname) != -1){ links[i].parentNode.className = 'link select_page'; } } }else{ links[0].parentNode.className = 'link select_page'; } })();