<div class="b1"></div>
<div class="b2"></div>
<div class="b3"></div>
function create(htmlStr){
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild){
frag.appendChild(temp.firstChild);
}
return frag;
}
var _bM=document.getElementsByClassName('.b'+1);
_bM.appendChild(create('<img src="'+some_data+'"class="q q'+some_var+'"/>'));
Uncaught TypeError: Object #<NodeList> has no method 'appendChild'
getElementsByClassName方法( 'EL')[0]未定義
其中爲:
var _bM=document.getElementsByClassName('.b'+1)[0];
Uncaught TypeError: Cannot call method 'appendChild' of undefined
im on chrome version 31.我試圖做純JavaScript而不是jquery,因爲我需要速度並且必須使用class not id。爲什麼發生這種情況?
類名不包含'.'。 – Zeta