-1
我是vue.js的新手,我有一個查詢。如何在vue.js中獲得href屬性值
我們如何獲得HTML變量的href
屬性值。
<pre>
var custompath = '<a href="undefined111">a8AZCtgt</a>'
</pre>
在此先感謝
我是vue.js的新手,我有一個查詢。如何在vue.js中獲得href屬性值
我們如何獲得HTML變量的href
屬性值。
<pre>
var custompath = '<a href="undefined111">a8AZCtgt</a>'
</pre>
在此先感謝
你可以做一個從無到有格,設置其innerHTML
到HTML,然後拿到要麼href
屬性(這將是完整的計算URL)或屬性(只是字符串,就像你指定的那樣)來自第一個子節點。
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'));