设置动态创建的纸张按钮的 class 不起作用

Setting the class of a dynamically created paper-button doesn't work

我有以下动态创建纸张按钮的代码。它运行良好,但我不知道如何设置 class。

var button = document.createElement('paper-button');
button.raised = true;
Polymer.dom(button).textContent = 'dynamic';
Polymer.dom(button).innerHTML = "New Button Text";    
$(".notificationCollection").append(button);

这不起作用:

Polymer.dom(button).class = "notificationBarButton";

我在文档中找不到任何内容。谢谢。

我偶然发现了答案。

button.setAttribute("class", "notificationBarButton");

此外,您可以使用

Polymer.dom(button).className = "notificationBarButton";

甚至

Polymer.dom(button).classList.add("notificationBarButton");

classList 有更多功能 .remove.toggle.

类列表的文档:https://developer.mozilla.org/en-US/docs/Web/API/Element/classList