jquery
  • getjson
  • 2010-11-21 58 views 0 likes 
    0

    我想創建一個使用jquery的鏈表。我正在使用此代碼來檢索日期使用jquery檢索鏈接

    $.getJSON('/chapersRetrival.php', function(data) 
         { 
          $.each(data, function(index, array) {  
          $("<a/>").attr({href: 'http://www.mangamanga.com/chapNo='+array['chapterID']+'&#pageNo=1>', title:array['mangaName'] + array['chapterName']} + array['chapterNumber']).appendTo("#mangaChpaters"); 
          }); 
         }); 
    

    只是想知道在編寫代碼時是否有任何問題?

    +0

    這一點看起來很可疑:'&#您做生意= 1>'你打算,做一個查詢參數(然後刪除''#),或'location.hash'(然後取出'&')。此外,右尖括號看起來不合適。 – Eric 2010-11-21 13:33:41

    回答

    1

    過早關閉}。需要在連接array['chapterNumber']之後來。否則對我來說看起來很好。

    的修復:

    $.getJSON('/chapersRetrival.php', function(data) 
         { 
          $.each(data, function(index, array) {  
           $("<a/>").attr({href: 'http://www.mangamanga.com/chapNo='+array['chapterID']+'&#pageNo=1>', title:array['mangaName'] + array['chapterName'] + array['chapterNumber']}).appendTo("#mangaChpaters"); 
          }); 
    }); 
    
    +0

    他並沒有試圖*選擇*所有錨點,他試圖創建一個錨點 - 最後他將新鑄造的錨點附加到'#mangaChpaters' [原文如此]。元素創建的語法是將HTML字符串傳遞給jQuery函數。 – 2010-11-21 08:58:47

    0

    那麼一開始,你可以把它更可讀,加入了一些換行。此外,this指針可以被用作函數裏面的簡寫指向當前的數據塊:

    $.getJSON('/chapersRetrival.php', function(data) { 
        $.each(data, function() {  
         $("<a/>").attr({ 
          href: 'http://www.mangamanga.com/chapNo='+this['chapterID']+'&#pageNo=1>', 
          title: this['mangaName'] + this['chapterName'] + this['chapterNumber'] 
         }).appendTo("#mangaChpaters"); 
        }); 
    }); 
    

    而且,你似乎已經做了幾個拼寫錯誤/錯別字,已被「雙規「在這裏:

    $.getJSON('/chaptersRetrieval.php', function(data) { 
        $.each(data, function() {  
         $("<a/>").attr({ 
          href: 'http://www.mangamanga.com/chapNo='+this['chapterID']+'#pageNo=1', 
          title: this['mangaName'] + this['chapterName'] + this['chapterNumber'] 
         }).appendTo("#mangaChapters"); 
        }); 
    }); 
    
    相關問題