Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   В Crome не работает style.borderRight (https://javascript.ru/forum/dom-window/43874-v-crome-ne-rabotaet-style-borderright.html)

NMitra 24.12.2013 19:53

В Crome не работает style.borderRight
 
Почему не работает в Хроме и как бы это исправить?

<div id="itog1" style="width: 120px; height: 120px; margin: 0 auto; border: medium solid rgb(34, 34, 34);"></div>

<pre>
top: <span></span>
right: <span></span>
bottom: <span></span>
left: <span></span>
</pre>

<script>
var itog = document.querySelector('#itog1');
window.onload = function () {
  document.querySelector('pre span:nth-of-type(1)').innerHTML = itog.style.borderTop;
  document.querySelector('pre span:nth-of-type(2)').innerHTML = itog.style.borderRight;
  document.querySelector('pre span:nth-of-type(3)').innerHTML = itog.style.borderBottom;
  document.querySelector('pre span:nth-of-type(4)').innerHTML = itog.style.borderLeft;
}
</script>

рони 24.12.2013 20:20

NMitra,
getComputedStyle

рони 24.12.2013 20:34

NMitra,
либо искать то что установили
Цитата:

borderTopColor rgb(34, 34, 34)
borderTopStyle solid
borderTopWidth 3px

NMitra 24.12.2013 22:53

С getComputedStyle ещё хуже получилось ((

Да, верно, вы правы, спасибо:

<div id="itog1" style="width: 120px; height: 120px; margin: 0 auto; border: medium solid rgb(34, 34, 34);"></div>

<pre>
top <span></span>
right <span></span>
bottom <span></span>
left <span></span>
</pre>

<script>
var itog = document.querySelector('#itog1');
window.onload = function () {
  document.querySelector('pre span:nth-of-type(1)').innerHTML = itog.style.borderTop;
  document.querySelector('pre span:nth-of-type(2)').innerHTML = itog.style.borderRightWidth + ' ' + itog.style.borderRightStyle + ' ' + itog.style.borderRightColor;
  document.querySelector('pre span:nth-of-type(3)').innerHTML = itog.style.borderBottomWidth + ' ' + itog.style.borderBottomStyle + ' ' + itog.style.borderBottomColor;
  document.querySelector('pre span:nth-of-type(4)').innerHTML = itog.style.borderLeftWidth + ' ' + itog.style.borderLeftStyle + ' ' + itog.style.borderLeftColor;
}
</script>

Яростный Меч 24.12.2013 23:03

Цитата:

Сообщение от NMitra
С getComputedStyle ещё хуже получилось ((

http://jsfiddle.net/v5pMU/

что любопытно - здесь на форуме не работает, если оформить код со словом "run"

danik.js 25.12.2013 05:43

Цитата:

Сообщение от Яростный Меч
что любопытно - здесь на форуме не работает, если оформить код со словом "run"

А в консоль в детстве не учили заглядывать, товарищ программист, а?

Цитата:

Uncaught SyntaxError: Unexpected token & [showhtml:14]
Ты зачем неразрывные пробелы в коде используешь?


Вот почищенный код:
<div id="itog1" style="width: 120px; height: 120px; margin: 0 auto; border: medium solid rgb(34, 34, 34);"></div>
 
<pre>
top <span></span>
right <span></span>
bottom <span></span>
left <span></span>
</pre>
 
<script>
(function () {
  var itog = document.querySelector('#itog1');
  var compStyle = getComputedStyle(itog, "");
  document.querySelector('pre span:nth-of-type(1)').innerHTML = compStyle.borderTop;
  document.querySelector('pre span:nth-of-type(2)').innerHTML = compStyle.borderRight;
  document.querySelector('pre span:nth-of-type(3)').innerHTML = compStyle.borderBottom;
  document.querySelector('pre span:nth-of-type(4)').innerHTML = compStyle.borderLeft;
})();
</script>


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