Пока вы ждете книг!
Учитесь у Центр разработчиков Mozilla !
Пример:
Пример
Фиксированная версия
document.write(
'Once upon a time there was a ' + heroGender +
' named ' + heroName + '.' + '<BR>' + heroName +
' had a ' + petType + ' called ' + petName + '.');
Разбитая версия
Выотсутствовали до +
символов.
document.write(
'Once upon a time there was a ' + heroGender +
' named ' + heroName /* + */ '.' /* + */ '<BR>' + heroName +
' had a ' + petType + ' called ' + petName + '.');
Попробуйте использовать
- Firefox и Firebug и его вкладку консоли (Hit F12)
- IE9 и встроенная консоль (нажмите F12. Убедитесь, что консоль открыта, затем обновите).
- Chrome и встроенную консоль (нажмите Ctrl + Shift + J)
Следить за сообщениями об ошибках.
Если это слишком много, попробуйте
window.onerror = function(e) {
alert(e.message);
}
Вот "улучшенная" версия, соответствующая стандартам. Пример ссылки!
HTML:
<label> Your Hero's gender </label><input id="heroGender"/><br/>
<label> Your Hero's name </label><input id="heroName"/><br/>
<label> Your Hero's pet type </label><input id="petType"/><br/>
<label> Your Hero's pet name </label><input id="petName"/><br/>
<button> Make me a hero! </button>
<div id="output"></div>
JavaScript:
// make your hero when you press the button
document.getElementsByTagName("button")[0].addEventListener("click", function() {
// get all the values from the text boxes
var gender = document.getElementById("heroGender").value,
name = document.getElementById("heroName").value,
petType = document.getElementById("petType").value,
petName = document.getElementById("petName").value;
// set the text on your output.
document.getElementById("output").textContent =
"Once upon a time there was a " + gender +
" named " + name + ". " + name + " had a pet " +
petType + " called " + petName;
}, false);
Theприведенный выше код сломается для IE8 или менее :(. Заставить JavaScript работать в кросс-браузерном режиме - правильная задача.
Так что вы можете прочитать документацию для браузеров по адресу
Но их нелегко читать или перемещаться.Руководство по кросс-браузерному написанию сценариев - visibone BrowserBook .
В нем будет показана поддержка кросс-браузеров (красный - firefox, синий - IE):
Дайте ему несколько месяцев, и вы узнаете, как все это удобно использовать.