【问题标题】:Dartlang attach link to LIElementDartlang 将链接附加到 LIElement
【发布时间】:2013-11-29 10:23:24
【问题描述】:

是否可以将LIElement做成链接,如何实现?

我试过了

var li = new LIElement();
li.text = text;
li.href = "http://www.google.com";

但它似乎不起作用。

任何帮助将不胜感激。

【问题讨论】:

    标签: dart


    【解决方案1】:

    您必须添加一个锚元素,就像在 HTML 中那样。

    LIElement li = new LIElement();
    AnchorElement a = new AnchorElement();
    a.text = "I'm a <li> with an <a>!";
    a.href = "http://www.google.com";
    li.append(a);
    

    【讨论】:

    • 我没有使用 append(),而是使用了 children.add()。谢谢!
    【解决方案2】:

    LIElement 上没有 href 设置器。或者,您可以在点击时添加一个监听器以更改页面的位置。

    var li = new LIElement();
    li.text = text;
    li.onClick.listen((e) => window.location.assign("http://www.google.com"));
    

    【讨论】:

      猜你喜欢
      • 2012-10-16
      • 2011-02-05
      • 2017-07-22
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-27
      相关资源
      最近更新 更多