问答详情
源自:3-3 优化与扩展

加入“main_background”图片展示样式失效 无图片显示

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');获取正常

提问者:慕函数6472736 2015-06-27 20:12

个回答

  • 黑涩丶co
    2015-11-27 20:19:14

    <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>

    求教怎么会是这样呢

  • Young0123456
    2015-10-14 23:35:59

    replace(/{{index}}/g,'{{index}}').replace(/{{h2}}/,'{{h2}}').replace(/{{h3}}/,'{{h3}}')正解!赞,并且遍历个数确实要用clear_ctrl[i]!

  • 默克法塔赫
    2015-07-02 17:32:52

    replace(/{{index}}/g,'{{index}}').replace(/{{h2}}/,'{{h2}}').replace(/{{h3}}/,'{{h3}}')