var changechannellist = function () { this.otarget = ""; this.selectcss = ""; this.ifdefaultfirst = "yes"; var that = this; this.run = function () { var url = location.href; var alistson = $(that.otarget); if (that.ifdefaultfirst == "yes") { alistson.eq(0).addclass(that.selectcss); } var temp = that.check(url, alistson, alistson, 0, 0); //alert(temp); if (temp != "false") { alistson.each(function () { $(this).removeclass(that.selectcss); }) alistson.eq(temp).addclass(that.selectcss); } } this.check = function (url, allobj, obj, urlcursor, acursor) { //杩欎釜鏂规硶鏄负浜嗗姣擴rl鍜岃秴閾炬帴缁勫悎鐨凥ref鐨勭浉浼煎害銆傜劧鍚庢壘鍒版渶鐩镐技鐨勪竴涓紝瀵规瘮鏂规硶鏈変粠鍚庡悜鍓嶉€愪釜瀵规瘮锛宑ursor灏辩浉褰撲簬涓€涓父鏍� var brotherflag = 0; //鎺掗櫎鍚岀骇鍚屽悕瀛愭爮鐩€傚鏋滃悕绉扮浉鍚岋紝闇€瑕佸姣斾笂涓€绾ф爮鐩紝鐩村埌纭畾鍞竴銆� var temparray = url.split("/"); var targetindexnum = 0; //閫夊彇鐨勭殑瓒呴摼鎺ョ殑绱㈠紩鍊� var currenturlbranch; //褰撳墠瑕佹瘮杈僓rl鐨勯儴鍒� if (temparray[temparray.length - 1] == "" || temparray[temparray.length - 1].match(".html")) { if (urlcursor == 0) { urlcursor++; } } currenturlbranch = temparray[temparray.length - 1 - urlcursor]; var tempobj = $(); obj.each(function () { var shref = $(this).attr("href").split("/"); if (shref[shref.length - 1] == "" || shref[shref.length - 1].match(".html")) { if (acursor == 0) { acursor++; } } //alert(shref[shref.length-1-cursor]) var currentabranch = shref[shref.length - 1 - acursor]//褰撳墠瑕佹瘮杈僅ref鐨勯儴鍒� if (currenturlbranch == currentabranch) { tempobj.push($(this)); //灏嗙鍚堣姹傜殑a瑁呰繘涓€涓柊鐨勫璞★紝杩欐牱鍙互鍑忓皯涓嬩竴娆″惊鐜殑鏁伴噺銆� targetindexnum = allobj.index($(this)); //璁板綍绗﹀悎鏉′欢鐨勮秴閾炬帴鍦ㄦ渶鍒濈殑瀵硅薄涓殑绱㈠紩浣嶇疆锛屼互渚胯繑鍥炪€� brotherflag++; } }); if (brotherflag > 1) { urlcursor = urlcursor + 1; acursor = acursor + 1; return that.check(url, obj, tempobj, urlcursor, acursor); } else if (brotherflag == 1) { return targetindexnum; } else if (brotherflag == 0) { return "false"; } } }