如何在聚合物自定义元素中使用getElementById?getElementById聚合物元素
这里是我的元素:
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../styles/shared-styles.html">
<dom-module id="bb-calendar">
<template>
<style is="custom-style" include="shared-styles"></style>
<div class="card">
<paper-toolbar>
<div title>Calendar</div>
</paper-toolbar>
<div id="hideme">
<div>this should be hidden</div>
</div>
</div>
</template>
<script>
Polymer({
is: 'bb-calendar',
ready: function() {
document.getElementById("hideme").style.display = 'none';
}
});
</script>
</dom-module>
当我运行代码,我收到此错误信息:Uncaught TypeError: Cannot read property 'style' of null
很显然,我做错了什么,但我不知道是什么。
感谢您的帮助!解决问题的方式就像你在上一个答案中所做的一样(其他人不为我工作)。 1.修正了“in the class name。2. instead of properties I used used'this.hiddenClass'。Thanks again。 –
感谢您的反馈并为错误而感到遗憾,我自己只使用Dart。 –
我相信正确的语法'ready'处理程序是'this。$。hideme'和'this。$$('#hideme')'。 –