Javascript 从聚合物元素中获得这种风格
只是学习聚合物。我想抓住固定标题的颜色,当它被点击Javascript 从聚合物元素中获得这种风格,javascript,html,css,polymer,Javascript,Html,Css,Polymer,只是学习聚合物。我想抓住固定标题的颜色,当它被点击 <link rel="import" href="../polymer/polymer.html"> <polymer-element name="fixed-header" attributes="height" style="background-color:blue"> <template> <style> :host { display: b
<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>
:主持人{
显示:块;
背景色:红色;
}
::内容*{
列表样式类型:无;
}
聚合物(“固定头”{
changeColor:function(){
var color=this.style.backgroundColor
console.log(彩色)
}
});
当我在聚合物元素上不使用内联样式时,我不能使用这个.style.backgroundColor,即使它肯定会将颜色更改为红色。为什么我不能使用这个.style.backgroundColor,而它只是通过模板样式标记
另外,我正在尝试设置backgroundColor,但我也不能这样做。返回节点
style
属性内容的对象表示是style
属性的关键。你想要的是:
这是一个例子
对于您的第二条评论,请在Chrome 36和38中为我设置style
var color = getComputedStyle(this).backgroundColor;