2012-02-15 105 views
0

所有其他浏览器(Chrome 17,Firefox,IE9)都能正常工作。 IE7给我一个脚本错误在“行80字符6”。这是我上线的脚本,根据代码开头的注释。我不知道很多JavaScript,但我没有看到任何线80字符6.代码是在这里:无法找到javascript错误 - IE7提供脚本/运行时错误

// tumblrBadge by Robert Nyman, http://www.robertnyman.com/, http://code.google.com/p/tumblrbadge/ 
var tumblrBadge = function() { 
    // User settings 
    var settings = { 
     userName : "rs2006db", // Your Tumblr user name 
     itemsToShow : 5, // Number of Tumblr posts to retrieve 
     itemToAddBadgeTo : "tumblr", // Id of HTML element to put badge code into 
     imageSize : 100, // Values can be 75, 100, 250, 400 or 500 
     shortPublishDate : true, // Whether the publishing date should be cut shorter 
     timeToWait : 2000 // Milliseconds, 1000 = 1 second 
    }; 

    // Badge functionality 
    var head = document.getElementsByTagName("head")[0]; 
    var badgeContainer = document.getElementById(settings.itemToAddBadgeTo); 
    if (head && badgeContainer) { 
     var badgeJSON = document.createElement("script"); 
     badgeJSON.type = "text/javascript"; 
     badgeJSON.src = "http://" + settings.userName + ".tumblr.com/api/read/json?callback=tumblrBadge.listItems&num=" + settings.itemsToShow; 
     head.appendChild(badgeJSON); 

     var wait = setTimeout(function() { 
      badgeJSON.onload = null; 
      badgeJSON.parentNode.removeChild(badgeJSON); 
      badgeJSON = null; 
     }, settings.timeToWait); 

     listItems = function (json) { 
      var posts = json.posts, 
       list = document.createElement("ul"), 
       title, 
       titletext, 
       post, 
       listItem, 
       text, 
       link, 
       img, 
       conversation, 
       postLink; 
      list.className = "tumblr"; 
      for (var i=0, il=posts.length; i<il; i=i+1) { 
       post = posts[i]; 

       // Only get content for text, photo, quote and link posts 
       if (/regular|photo|quote|link|conversation/.test(post.type)) { 


        listItem = document.createElement("p"); 
        title = post["title"]; 
        text = post["regular-body"] || post["photo-caption"] || post["quote-source"] || post["link-text"] || post["link-url"] || ""; 
        if (post.type === "photo") { 
         link = document.createElement("a"); 
         link.href = post.url; 
         img = document.createElement("img"); 
         // To avoid a creeping page 
         img.width = settings.imageSize; 
         img.src = post["photo-url-" + settings.imageSize]; 
         link.appendChild(img); 
         listItem.appendChild(link); 
         text = "<em>" + text + "</em>"; 
        } 
        else if (post.type === "quote") { 
         text = post["quote-text"] + "<em>" + text + "</em>"; 
        } 
        else if (post.type === "link") { 
         text = '<a href="' + post["link-url"] + '">' + text + '</a>'; 
        } 
        else if (post.type === "conversation") { 
         conversation = post["conversation-lines"]; 
         for (var j=0, jl=conversation.length; j<jl; j=j+1) { 
          text += conversation[j].label + " " + conversation[j].phrase + ((j === (jl -1))? "" : "<br>"); 
         } 
        } 
        if (post.type === "regular") { 
         text = "<strong>" + post["regular-title"]+ "</strong>" + text; 
         text = "" + post["date"] + " - " + text; 
         text = "<br />" + text; 
        } 

        listItem.innerHTML += text || ""; 

        // Apply list item to list 
        list.appendChild(listItem); 
       } 
      } 

      // Apply list to container element 
      badgeContainer.innerHTML = ""; 
      badgeContainer.appendChild(list); 
     }; 

     return { 
      listItems : listItems 
     }; 
    } 
}(); 
+0

在Visual Studio中使用脚本调试器。 – SLaks 2012-02-15 05:31:28

+0

在'firefox'中使用'firebug',它也会在'IE'中工作 – maxjackie 2012-02-15 05:34:37

+0

IE6和7在使用innerHTML时遇到了问题,这是关于比其他浏览器更严格地执行事情的问题。信息可以在[这里]找到(http://blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html)。 – taylorthurlow 2012-02-15 07:00:04

回答

0

尝试替换这一行(80):

listItem.innerHTML + =文本|| “”;

有了:

listItem.innerHTML =文字? listItem.innerHTML + text:“”;

相关问题