技巧分析:用javascript 转换外部CSS超级链接样式
点击次数:30 次 发布日期:2008-11-26 19:54:36 作者:源代码网
|
源代码网推荐 源代码网推荐但用css有弊端: 源代码网推荐1、只支持FireFox等对web标准支持很好的浏览器。 源代码网推荐2、只能判断链接,不能判断锚点或javascript。如遇到<a href="javascript:void(0);">就无能为力了。 源代码网推荐 源代码网推荐这里可以结合js来完成,首先写一个样式: 源代码网推荐 a.other:link,a.other:visited,a.other:active 源代码网推荐{ 源代码网推荐background:url("external.gif") no-repeat top right; 源代码网推荐padding-right:15px; 源代码网推荐} 源代码网推荐再写一个js,但js要考虑到链接的多样性,如上面提到的javascript、锚点等。 如果是图片链接,就不要应用样式了。 源代码网推荐 <script type="text/javascript"> 源代码网推荐window.onload = function() 源代码网推荐{ 源代码网推荐var aList = document.getElementsByTagName("a"); 源代码网推荐var iCount = aList.length; 源代码网推荐for(var i = 0;i<iCount;i++) 源代码网推荐{ 源代码网推荐 源代码网推荐if(!chkMyLink(aList[i].href,aList[i].innerHTML)) 源代码网推荐{ 源代码网推荐aList[i].className ="other"; 源代码网推荐} 源代码网推荐} 源代码网推荐} 源代码网推荐 源代码网推荐//s是链接的url,innerhtml是链接文本 源代码网推荐function chkMyLink(s,innerhtml) 源代码网推荐{ 源代码网推荐if(innerhtml.replace( /^s*/,"").match(/^<img/gi)) return true; 源代码网推荐var reg = /^http:///gi; 源代码网推荐if(s.match(reg)) 源代码网推荐{ 源代码网推荐reg = /^http://www.webjx.com/gi; 源代码网推荐if(s.match(reg)) 源代码网推荐{ 源代码网推荐return true; 源代码网推荐} 源代码网推荐else 源代码网推荐{ 源代码网推荐return false; 源代码网推荐} 源代码网推荐} 源代码网推荐return true; 源代码网推荐} 源代码网推荐</script> 源代码网推荐现在可以看到效果了。 源代码网供稿. |
