Выдрать значение стиля
Здравствуйте. Не могу узнать значение стиля. Стиль естественно в .css файле. Нужно чтобы значение Background-Color блока div вбивалось в текстовое поле. Сейчас выглядит примерно так:
document.form1.input1.value = document.getElementById('id').getStyle("background-color");
Фаерфокс и опера сжирают нормально, IE выдает ошибку на страницу и пишет "Объект не поддерживает это свойство или метод". Помогите пожалуйста поправить как надо. |
Как вариант...
document.form1.input1.value = document.getElementById('id').style.backgroundColor
; |
|
Не катит так. Стиль в файле же, а даже если бы не в файле то выдает rgb(255, 255, 255) вместо #FFFFFF :-?
|
<style type="text/css">
a {margin-left: 10px;}
</style>
<script type="text/javascript">
window.onload = function(){
document.getElementsByTagName('a')[0].onclick = function(){
alert(window.getComputedStyle(this, null).marginLeft || this.currentStyle.marginLeft)
};
return false;
};
</script>
<a href="#">Нажми на меня</a>
|
Возвращает цвет в формате rgb(255, 255, 255) :( Парсер дописывать?
|
Цитата:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<style type='text/css'>
div {
width: 100px;
height: 20px;
}
#b1 {
background-color: red;
}
#b2 {
background-color: rgb(200, 200, 200);
}
#b3 {
background-color: #f0f0f0;
}
</style>
<script type="text/javascript">
function Go() {
alert(getBackgroundColor('b1'))
alert(getBackgroundColor('b2'))
alert(getBackgroundColor('b3'))
}
function getBackgroundColor(Id) {
; // Получить первый абзац
var o = document.getElementById(Id)
var val
// Сначала попробовать IE API
if (o.currentStyle) {
val = o.currentStyle.backgroundColor;
} else if (window.getComputedStyle) {
// Иначе W3C API
val = window.getComputedStyle(o, null).backgroundColor;
}
return val
}
</script>
</head>
<body>
<div id='b1'></div>
<div id='b2'></div>
<div id='b3'></div>
<input type='button' value='Go' onclick='Go()' />
</body>
</html>
Цитата:
|
Цитата:
А вот в IE и опере работает |
Цитата:
Я-то смотрел именно в ИЕ и Опере... :) Ну тогда дальше только "копытами, копытами" (с) |
;) знач буду "копытами"
всем спс за помощь :) |
| Часовой пояс GMT +3, время: 02:48. |