-1
我有一個HTML字符串,我想獲取img元素並初始化它。從HTML對象獲取元素javascript
var discountItem = '<li class="sidebar-brand" style="font-weight: bold; color: #9999 class="col-item">' +
'<div class="post-img-content">' +
'<img src=" " class="img-responsive" id="mimo" />'+
'<span class="post-title">'+
'<b>Perfumes</b><br>'+
'<b>Clássico</b>'+
'</span>'+
'<span class="round-tag">-15%</span>'+
'</div>'+
'</li>';
var k = app.clone(discountItem);
var df = document.createDocumentFragment();
// create a placeholder node to hold the innerHTML
var el = document.createElement('body');
el.innerHTML = k;
// append to the document fragment
df.appendChild(el);
// execute .getElementById
console.log(df.getElementByClassName('img-responsive');
view += k;
clone : function(obj){
try{
var copy = JSON.parse(JSON.stringify(obj));
} catch(ex){
console.log("you are using an old navigator");
}
return copy;
}
我試過這個,但它不起作用。
我的目標是初始化圖像的src。 有人可以幫我嗎?
呈現的代碼有語法錯誤。最後一點是什麼,它與你的問題有什麼關係? –
我有一個HTML字符串,我想初始化它的一個元素。 我想添加一個src到img元素。 –
其中......與我上面的評論無關。 –