Сборка CSS кода
Надо пройти по всем тегам input с классом css_editor:
HTML: <input type="text" class="css_editor" data-ident=".wrap" data-edit="background" value="#fff" /> И составить одну строку: Код: Код:
.wrap { background: #fff; }.wrap из date-ident background из data-edit #fff из value UPD: Должно быть так: Код:
function array_event(item, i, arr){
window.styles = window.styles+"\n"+item.attr('data-ident')+' { '+item.attr('data-edit')+'; }'; // Добавляем данные в глобальную переменную
}
function plain_view(){
$('.edit_style').each(array_event); // Проходим по всем элементам с классом edit_style
}
Вызываем plain_view() и в глобальной переменной styles у нас стили из полей. Но почему то не работает http://jsfiddle.net/ggxkhmt6/5/ |
Цитата:
Цитата:
|
$ это jQuery, его то я подключаю. Ошибка
Uncaught TypeError: undefined is not a function (index):29 plain_view (index):29 (anonymous function) (index):31 jQuery.event.dispatch jquery-1.9.1.js:3074 elemData.handle http://jsfiddle.net/ggxkhmt6/5/ |
Q_BASIC, jQuery не возвращает массив, поэтому метода forEach быть не должно. Используй просто each.
|
Теперь ошибка на этой строчке:
window.styles = window.styles+"\n"+item.attr('data-ident')+' { '+item.attr('data-edit')+'; }';
Uncaught TypeError: undefined is not a function (index):210 array_event (index):210 m.extend.each jquery.js:2 m.fn.m.each jquery.js:2 plain_view (index):214 onclick |
function array_event(){
window.styles += "\n"+ this.dataset.ident + ' { ' + this.dataset.edit + '; }';
}
function plain_view(){
$('.edit_style').each(array_event);
}
|
Всё, спасибо.
Сделал:
function plain_view(){
window.styles = '';
$('.edit_style').each(function(){
window.styles = window.styles+"\n"+ $(this).attr('data-ident')+' { '+$(this).attr('data-edit')+': '+$(this).val()+'; }';
});
alert(window.styles);
}
|
А почему не?
function plain_view(){
window.styles = '';
$('.edit_style').each(function(){
window.styles += "\n"+ this.dataset.ident + ' { '+ this.dataset.edit + ': ' + this.value + ';}';
});
alert(window.styles);
}
|
dataset - не работает в старье.
Цитата:
|
Цитата:
|
| Часовой пояс GMT +3, время: 08:34. |