var mytitle = "";
mytitle = this.alt;
this.alt = "";当网页下载局部时,有时候mytitle的值为undefined,请问怎么解决?

解决方案 »

  1.   

    mytitle = typeof(this.alt)==undefined?"":this.alt;
      

  2.   

    mytitle = this.alt;
    上面一句话的位置要放到 this.alt赋值后的下面 
      

  3.   


    mytitle的值为undefined,说明this.alt值没拿到。
      

  4.   

    var mytitle = "";
    this.alt = "";
    mytitle = this.alt;
    顺序
     
      

  5.   

    不是顺序问题,如果
    var mytitle = "";
    this.alt = "";
    mytitle = this.alt;
    这样,那么mytitle就永远为空了!我试了二楼的作法,还是有问题,谢谢各位了。
      

  6.   

    var mytitle='';
    try {
    mytitle = this.alt;
    }
    catch(err){}这样不知行不?
      

  7.   


    if ($(this).attr("alt") == "undefined") {
                    $(this).attr({ "mytitle": "请刷新网页以加载说明文字……", "alt": "" });
                } else {
                    this.mytitle = this.alt;
                    this.alt = "";
                }这样解决了。
      

  8.   


    this.mytitle = (this.alt == "undefined" ? "请刷新网页以加载说明文字……" : this.alt);
    this.alt = "";最终的解决方案!