2013-01-08 35 views
1

我有一個模式,我上傳的圖像。
該圖像,然後返回這樣的:隱藏字段損失值使用jQuery的附加

<input type="hidden" value="20130108A70WY2.jpg" name="image_message_file" id="image_message_file"> 
<img src="http://files.gestionradioqc.com/immedia/message/picture/2013/01/08/20130108A70WY2_300.jpg"> 

我然後使用JavaScript這樣的數據傳輸到我的主頁:
< --EDITED - >

function addAttachmentsToMessage(){ 
    var picture = $("#image_message_preview").find('img').parent().html(); 
    alert(picture); 
    if(picture != ''){ 
     $("#message_attachments").append("<div class='attachment cf'>"+ 
             "<ul class='att-picture cf'>"+ 
              "<li>"+picture+"</li>"+ 
             "</ul>"+ 
            "</div>"); 
     clearAttachments(); 
    } 
} 

function clearAttachments(){ 
    $("#image_message_file").attr('value', ''); 
    $("#image-message").attr('value', ''); 
    $("#image_message_loading").hide(); 
    $("#image_message_upload").show(); 
    $("#image_message_preview").hide(); 
} 

< -/EDITED - >

警報實際上是正確的。
然而,究竟什麼被追加到message_attachments是(在隱藏字段沒有值):

<input type="hidden" value="" name="image_message_file" id="image_message_file"> 
<img src="http://files.gestionradioqc.com/immedia/message/picture/2013/01/08/20130108A70WY2_300.jpg"> 

但是,只有附加了第一圖像具有問題。
其他人都可以。
我在Firefox 17,Chrome 23和IE 9上遇到同樣的問題。

任何想法我的問題是什麼?

+0

你能否提供更多的上下文? 「image_message_preview」和「message_attachments」在哪裏? –

+0

你是故意遺漏了「if」還是代碼粘貼問題? –

+0

我發現了這個錯誤:我在隱藏的輸入上添加了一個id,並且有代碼(可惜這裏沒有顯示),它將根據id重新設置爲「」。因此只更改第一個找到的字段。 – ether

回答

0

我編輯我原來的職位,以顯示從哪裏傳來的錯誤。
錯誤來自我的函數clearAttachments(),它正在重置#image_message_file的值。由於它是通過id進行搜索的,因此它只是改變了第一個附加項目的值。
因此,我刪除了這一行,現在一切正常,因此函數現在是:

function clearAttachments(){ 
    $("#image-message").attr('value', ''); 
    $("#image_message_loading").hide(); 
    $("#image_message_upload").show(); 
    $("#image_message_preview").hide(); 
} 

感謝大家的見解!

0

$("#image_message_preview")無法訪問您發佈的標記 SO圖片警報「未定義」 - 因此您必須粘貼代碼/標記問題? 「image_message_file」

我把包裹/合適nameing等的自由和它的作品在這裏提醒值:

http://jsfiddle.net/eBTYC/

+0

它會出現#image_message_preview是img和輸入的父容器。我想他只是沒有發佈該代碼。 – davidethell

+0

@davidethell - 是的,看到我在小提琴中的假設......在這裏演奏的其他東西或只是壞的語法?我不知道...但這不僅僅是一個評論。 –

+0

同意。我沒有看到任何明顯的代碼錯誤,所以缺少一些東西。 – davidethell