【问题标题】:How to get href attributr value in vue.js如何在 vue.js 中获取 href 属性值
【发布时间】:2017-07-27 14:36:27
【问题描述】:

我是 vue.js 的新手,我有一个疑问。

我们如何获取 HTML 变量的href 属性值。

<pre>
    var custompath = '<a href="undefined111">a8AZCtgt</a>'
</pre>

提前致谢

【问题讨论】:

    标签: javascript vue.js


    【解决方案1】:

    您可以创建一个临时 div,将其 innerHTML 设置为您的 HTML,然后从第一个子节点。

    var custompath = '<a href="undefined111">a8AZCtgt</a>';
    const scratchDiv = document.createElement('div');
    scratchDiv.innerHTML = custompath;
    const a = scratchDiv.childNodes[0];
    console.log('Href prop:', a.href);
    console.log('Href attr:', a.getAttribute('href'));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 2022-11-18
      • 2013-10-03
      • 1970-01-01
      • 2018-05-06
      相关资源
      最近更新 更多