1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| <script type="text/javascript">
document.modElementsByReg=function(tag,attr,reg,mod,val){
var tabElts=document.body.getElementsByTagName(tag);
var TEL=tabElts.length;
if(!(reg instanceof RegExp)){
if(reg.indexOf("*")>-1){
reg=reg.replace(/\*/g,'.+');
reg=new RegExp(reg);
}
else {return false;
}
}
i=0;
while(tabElts[i]){
if(tabElts[i][attr]){
if(reg.test(tabElts[i][attr])){
tabElts[i].style[mod]=val;}
}
reg.test("");
i++;
}
}
</script>
<title>Nouvelle page 1</title>
</head>
<body >
<ul>
<li id="rub1" onclick="document.modElementsByReg('li','id',/^rub[23]$/,'backgroundColor','white');this.style.backgroundColor='blue'">rubrique1</li>
<li id="menu1" onclick="document.modElementsByReg('li','id',/^menu[2345]$/,'backgroundColor','white');this.style.backgroundColor='red'">menu1</li>
<li id="menu2" onclick="document.modElementsByReg('li','id',/^menu[1345]$/,'backgroundColor','white');this.style.backgroundColor='red'">menu2</li>
<li id="rub2" onclick="document.modElementsByReg('li','id',/^rub[13]$/,'backgroundColor','white');this.style.backgroundColor='blue'">rubrique2</li>
<li id="menu3" onclick="document.modElementsByReg('li','id',/^menu[1245]$/,'backgroundColor','white');this.style.backgroundColor='red'">menu3</li>
<li id="menu4" onclick="document.modElementsByReg('li','id',/^menu[1235]$/,'backgroundColor','white');this.style.backgroundColor='red'">menu4</li>
<li id="rub3" onclick="document.modElementsByReg('li','id',/^rub[12]$/,'backgroundColor','white');this.style.backgroundColor='blue'">rubrique1</li>
<li id="menu5" onclick="document.modElementsByReg('li','id',/^menu[1234]$/,'backgroundColor','white');this.style.backgroundColor='red'">menu5</li>
</ul>
</div>
</body>
</html> |
Partager