при отсутствии елемента код не работает
Почему оно работает только если все елементы isset ? если только какого-нибуть елемента который getElementById нету то все ппц не пашет...
function sortir() { var a = document.getElementById('id2O').style.top; var b = document.getElementById('id2D').style.top; var c = document.getElementById('id2S').style.top; if (a != '5px') { document.getElementById('id2O').style.top = "5px"; } else { document.getElementById('id2O').style.top = "44px"; } if (c != '5px') { document.getElementById('id2S').style.top = "5px"; } else { document.getElementById('id2S').style.top = "64px"; } if (b != '5px') { document.getElementById('id2D').style.top = "5px"; } else { document.getElementById('id2D').style.top = "84px"; } return false; } три линии находятся друг под другом по клику задаеться топ 5 по второму снова дефолт..Когда они все три линии есть все ок, как только какойто нету, не пашет =( |
новый вася,
что мешает проверить вначале есть линия или нет, если есть тогда работать со стилем. |
if (variable !== undefined) или есть какойто более приемлимый аналог PHPшного isset() ?
|
новый вася,
function sortir() { var a = document.getElementById("id2O"); var b = document.getElementById("id2D"); var c = document.getElementById("id2S"); if (a) if (a.style.top != "5px") a.style.top = "5px"; else a.style.top = "44px"; if (b) if (b.style.top != "5px") b.style.top = "5px"; else b.style.top = "64px"; if (c) if (c.style.top != "5px") c.style.top = "5px"; else c.style.top = "84px"; return false }; |
if(document.getElementById('id2O') !== 'undefined') { if (a != '5px') { document.getElementById('id2O').style.top = "5px"; } else { document.getElementById('id2O').style.top = "44px"; }} if(document.getElementById('id2S') !== 'undefined') { if (c != '5px') { document.getElementById('id2S').style.top = "5px"; } else { document.getElementById('id2S').style.top = "64px"; }} if(document.getElementById('id2D') !== 'undefined') { if (b != '5px') { document.getElementById('id2D').style.top = "5px"; } else { document.getElementById('id2D').style.top = "84px"; }}не работает еси поставить вместо гет елемент буквы а в и т.д. не работает чето не то пишу походу |
ща чекну сяп
|
новый вася,
if(document.getElementById('id2O') !== null) |
Цитата:
|
Цитата:
|
Часовой пояс GMT +3, время: 18:07. |