Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Uncaught SyntaxError: Unexpected identifier (https://javascript.ru/forum/misc/39508-uncaught-syntaxerror-unexpected-identifier.html)

serg123 02.07.2013 17:56

Uncaught SyntaxError: Unexpected identifier
 
Возникла проблема со скриптом вывода случайного фонового изображения в определенном айдишнике. Хром выдает ошибку Uncaught SyntaxError: Unexpected identifier и ссылается на строку document.getElementById:

Выглядит все примерно так:

<body>

<div id="fon"></div>

<script type="text/javascript" language="Javascript">
var backgrounds=array();
backgrounds[0]="/img/back_web.png";
backgrounds[1]="/img/back_web2.png";
var rand=Math.Round(Math.Rand()*backgrounds.length);
document.getElementById('fon').style.background='u rl('backgrounds[rand]') bottom no-repeat';
</script>

</body>

ruslan_mart 02.07.2013 18:15

var backgrounds = new Array();
backgrounds[0] = '/img/back_web.png';
backgrounds[1] = '/img/back_web2.png';
var rand = Math.Round(Math.Rand()*backgrounds.length);
document.getElementById('fon').style.background = 'url('+backgrounds[rand]+') bottom no-repeat';

рони 02.07.2013 18:46

Цитата:

Сообщение от serg123
var rand=Math.Round(Math.Rand()*backgrounds.length);

нет таких функций!!! :cray:
<!DOCTYPE HTML>
<html>
<head>
  <title>Untitled</title>
<style type="text/css">
div{
  height: 30px;
  width: 30px;
}

</style>
</head>

<body>
<div id="fon"></div>

 <script>
var backgrounds = new Array();
backgrounds[0] = 'http://javascript.ru/forum/images/smilies/agree.gif';
backgrounds[1] = 'http://javascript.ru/forum/images/smilies/cray.gif';
var rand = Math.floor(Math.random()*backgrounds.length);
document.getElementById('fon').style.background = 'url('+backgrounds[rand]+') bottom no-repeat';
  </script>
</body>

</html>

serg123 02.07.2013 19:37

Ruslan_xDD,
рони,
Спасибо огромное за помощь и извиняюсь за свое нубство.
Тему можно закрывать.


Часовой пояс GMT +3, время: 02:44.