g('template_main').innerHTML+=tpl_main .replace(/{{index}}/g,'{{index}}') .replace(/{{h1}}/g,data[i].h1) .replace(/{{h2}}/g,data[i].h2); g('main_{{index}}').id='main_background';
做完这步后,大图片无显示(控制按钮缩略图正常),不能加载main-i_active样式,这是为何?
var clean_main=g('.main-i'); var clean_ctrl=g('.ctrl-i'); for(i=0;i<clean_main.length;i++) { clean_ctrl[i].className=clean_ctrl[i].className .replace(' ctrl-i_active',""); clean_main[i].className=clean_main[i].className .replace(' main-i_active',""); } main.className+=' main-i_active'; ctrl.className+=' ctrl-i_active'; 即这部分代码失效,g('.main-i');获取正常
<div class="main-i" id="main_background">
<div class="caption">
<h2>Crazy</h2>
<h3>FRIEND</h3>
</div>
<img src="../img/{{index}}.jpg" class="picture" style="margin-top: -674.5px;">
</div>
求教怎么会是这样呢
replace(/{{index}}/g,'{{index}}').replace(/{{h2}}/,'{{h2}}').replace(/{{h3}}/,'{{h3}}')正解!赞,并且遍历个数确实要用clear_ctrl[i]!
replace(/{{index}}/g,'{{index}}').replace(/{{h2}}/,'{{h2}}').replace(/{{h3}}/,'{{h3}}')