代码之家  ›  专栏  ›  技术社区  ›  cusspvz

引用jQuery中的每个对象

  •  0
  • cusspvz  · 技术社区  · 16 年前

    我有 asked a question 关于引用jquery中的函数中的对象每个函数之前都在数组中定义了第一个函数。

    在我的问题中,一切都正常(因为我只使用一个元素进行测试),当我放入两个元素时,它不起作用,它总是调用第一个元素。

    谁能给我点火吗?

    var $d=null;
    var configs={
      general:{
        selector:'div.MicrodualAdGet',
        max_ads:6},
      logs:{
        selector:'div#MicrodualAdGet-debug'},
      connection:{
        type:'POST',
        url:'http://www.microdual.com/api/microdualgetad',
        cache:false,
        timeout:20000,
        dataType:'json',
        data:{
          adget_id:null,
          client_action:null},
        error:function(r,s,e){MicrodualAdGet_Log("Ajax-Error: "+s+"\n");},
        success: null
      }
    };
    function MicrodualAdGet_Log(msg){$(configs.logs.selector).append(msg);}
    function MicrodualAdGet_View(d,s){
      if(! d) {
        MicrodualAdGet_Log("MicrodualAdGet-Error: Couldn't contact server correctly\n");
        $d.replaceWith("MicrodualAdGet Error: Couldn't contact server correctly");
      }else{
        if(d.hackattemp.status){
          MicrodualAdGet_Log("MicrodualAdGet-Hackattemp-Error: "+d.hackattemp.id+"\n");
          $d.replaceWith("MicrodualAdGet Hackattemp Error: "+d.hackattemp.id);
        }else{
          var content='';
          $d.css({
            display: 'block',
            position: 'relative',
            width: d.tamanhos[d.adpost.id_tamanho].width,
            height: d.tamanhos[d.adpost.id_tamanho].height,
            overflow: 'hidden',
            top: '0px',
            left: '0px',
            background: '#000000'
          })
          if(d.tipos[d.adpost.id_tipo].nome_tipo=='text') content=d.adpost.content;
          if(d.tipos[d.adpost.id_tipo].nome_tipo=='image') content='<a href="'+d.adpost.link+'" target="_blank"><img src="'+d.adpost.content+'" width="'+d.tamanhos[d.adpost.id_tamanho].width+'" height="'+d.tamanhos[d.adpost.id_tamanho].height+'" border="0" /></a>';
          if(content=='') content='MicrodualAdGet Error: Unable to determine ad type. Please contact our <a href="mailto:network@microdual.com">Network Administrator</a>';
          $d.replaceWith(content);
        }
      }
    }
    
    
    
    configs.connection.success = MicrodualAdGet_View;
    configs.connection.data.client_action = "view";
    $(configs.general.selector).each(function(){
      $d=$(this);
      configs.connection.data.adget_id=$(this).attr("rel");
      $.ajax(configs.connection);
    });
    

    提前谢谢,

    1 回复  |  直到 9 年前
        1
  •  0
  •   cusspvz    16 年前

    固定的, async:false 在 config.connection 数组。。。

    var $d=null;
    var configs={
      general:{
        selector:'div.MicrodualAdGet',
        max_ads:6},
      logs:{
        selector:'div#MicrodualAdGet-debug'},
      connection:{
        type:'POST',
        url:'http://www.microdual.com/api/microdualgetad',
        cache:false,
        async:false,
        timeout:20000,
        dataType:'json',
        data:{
          adget_id:null,
          client_action:null},
        error:function(r,s,e){MicrodualAdGet_Log("Ajax-Error: "+s+"\n");},
        success: null
      }
    };
    function MicrodualAdGet_Log(msg){$(configs.logs.selector).append(msg);}
    function MicrodualAdGet_View(d,s){
      if(! d) {
        MicrodualAdGet_Log("MicrodualAdGet-Error: Couldn't contact server correctly\n");
        $d.replaceWith("MicrodualAdGet Error: Couldn't contact server correctly");
      }else{
        if(d.hackattemp.status){
          MicrodualAdGet_Log("MicrodualAdGet-Hackattemp-Error: "+d.hackattemp.id+"\n");
          $d.replaceWith("MicrodualAdGet Hackattemp Error: "+d.hackattemp.id);
        }else{
          var content='';
          $d.css({
            display: 'block',
            position: 'relative',
            width: d.tamanhos[d.adpost.id_tamanho].width,
            height: d.tamanhos[d.adpost.id_tamanho].height,
            overflow: 'hidden',
            top: '0px',
            left: '0px',
            background: '#000000'
          })
          if(d.tipos[d.adpost.id_tipo].nome_tipo=='text') content=d.adpost.content;
          if(d.tipos[d.adpost.id_tipo].nome_tipo=='image') content='<a href="'+d.adpost.link+'" target="_blank"><img src="'+d.adpost.content+'" width="'+d.tamanhos[d.adpost.id_tamanho].width+'" height="'+d.tamanhos[d.adpost.id_tamanho].height+'" border="0" /></a>';
          if(content=='') content='MicrodualAdGet Error: Unable to determine ad type. Please contact our <a href="mailto:network@microdual.com">Network Administrator</a>';
          $d.replaceWith(content);
        }
      }
    }
    
    
    
    configs.connection.success = MicrodualAdGet_View;
    configs.connection.data.client_action = "view";
    $(configs.general.selector).each(function(){
      $d=$(this);
      configs.connection.data.adget_id=$(this).attr("rel");
      $.ajax(configs.connection);
    });
    

    谢谢大家。。。

    推荐文章