<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="zh-cn">
<head>
<title>新窗口打开链接方式(可通过校验、灵活调用、代码简洁)</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<div class="blank">
<a href="">百度</a><br>
<a href="">谷歌</a><br>
<a href="">前端技术(JS部分由前端技术站长cssrain提供,俺不会JS)</a><br>
<a href="">理想男孩(没空整)</a>
</div>
<script type="text/javascript" src="blank.js"></script>
</body>
</html>
function ByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/-/g, "\-";
var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)";
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements;
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements);
}
var blanks = ByClassName(document, "*", "blank";
for (var i=0;i<blanks.length;i++ ){
var urls = blanks.getElementsByTagName("a";
for (var j=0;j<urls.length;j++ ){
urls[j].target="_blank";
}
}