Я новичок в программировании, и хотелось бы как правильней писать скрипты.
Скрипт1:
<script>
imgPath = "images/";
pictures = new Array("photo_1","photo_2","photo_3");
suffix = "_on";
extension = "jpg";
total = pictures.length;
On_Images = new Array();
Off_Images = new Array();
for (i = 0; i < total; i++) {
On_Images[pictures[i]] = new Image();
On_Images[pictures[i]].src = imgPath + pictures[i] + suffix + "." + extension;
Off_Images[pictures[i]] = new Image();
Off_Images[pictures[i]].src = imgPath + pictures[i] + "." + extension;
}
function on(name)
{
document.images[name].src = On_Images[name].src;
}
function off(name)
{
document.images[name].src = Off_Images[name].src;
}
</script>
__________________________________
Скрипт2:
<script>
var folder = 'images/'; var suffix_on = '_on';
function on(e_name{
var url_on = folder + e_name + suffix_on + '.jpg';
document.images[e_name].src = url_on;
}
function off(e_name){
var url_off = folder + e_name + '.jpg';
document.images[e_name].src = url_off;
}
</script>
_______________________________________
и сам html код:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>[06] Создание rollover–изображений</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h2>[06] Создание rollover–изображений</h2>
<p> </p>
<p><a href="#" onmouseover="on('photo_1');" onmouseout="off('photo_1');"><img src="images/photo_1.jpg" name="photo_1" width="130" height="98"></a></p>
<p><a href="#" onmouseover="on('photo_2');" onmouseout="off('photo_2');"><img src="images/photo_2.jpg" name="photo_2" width="130" height="98"></a></p>
<p><a href="#" onmouseover="on('photo_3');" onmouseout="off('photo_3');"><img src="images/photo_3.jpg" name="photo_3" width="130" height="98"></a></p>
</body>
</html>