如何使用 dart 更改 css 样式表?

and*_*lex 5 html css dart dart-polymer

我正在处理一个考试项目,我需要更改页面中样式表的名称。我怎样才能用 Dart 做到这一点?我已经看到我可以从 Dart 编辑我的 css 的每个属性,但我已经制作了我想在我的页面中使用的其他 css。例如,我的 html 页面中有这个:

<link href="stile.css" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)

我需要编辑页面才能做到这一点

<link href="stile-blu.css" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Gün*_*uer 4

假设你的<link ...>元素在<head>元素中

document.querySelector('#button').onClick.listen((_) {
  var stile = document.head.querySelector('link[href="stile.css"]');
  stile.attributes['href'] = 'stile-blu.css';
});
Run Code Online (Sandbox Code Playgroud)

如果您id向链接元素添加属性,则可以简化选择器

<link id="mystyle" href="stile.css" rel="stylesheet" type="text/css"> 
Run Code Online (Sandbox Code Playgroud)
document.querySelector('#button').onClick.listen((_) {
  var stile = document.head.querySelector('#mystyle');
  stile.attributes['href'] = 'stile-blu.css';
});
Run Code Online (Sandbox Code Playgroud)