【发布时间】:2014-08-08 03:35:44
【问题描述】:
刚刚学习聚合物。我想在单击时获取固定标题的颜色。
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="fixed-header" attributes="height" style="background-color:blue">
<template>
<style>
:host {
display: block;
background-color: red;
}
::content * {
list-style-type: none;
}
</style>
<header layout horizontal on-click="{{changeColor}}">
<content select="li"></content>
</header>
</template>
<script>
Polymer('fixed-header', {
changeColor: function() {
var color = this.style.backgroundColor
console.log(color)
}
});
</script>
</polymer-element>
当我不在聚合物元素上使用内联样式时,我不能使用 this.style.backgroundColor,即使它肯定会将颜色更改为红色。为什么只能通过模板样式标签使用this.style.backgroundColor?
另外,我正在尝试设置背景颜色,但我也做不到。
【问题讨论】:
标签: javascript html css polymer