2012-09-09 54 views
0

我有一個動態的形式......它有一個輸入字段類似的onclick jQuery的圖片ID,形成輸入字段

<form class="" 
<input name="image_0" .. /> 
<input name="image_1" .. /> 
<input name="image_4" .. /> 
<input name="image_6" .. /> 
<input name="image_7" .. /> 
.... 
</form> 

和我有一個又一個UL李塊從的Facebook相冊取得圖片.. 。當我們點擊圖像它的「身份證」具有填補空白輸入字段,並沒有重複選擇的任何人......對

圖片:Check this image may be it helps to understand

編輯:

<form class="fb_upload_id" method="get"> 
    image_2:<input name="image_2" type="text"> 
    image_3:<input name="image_3" type="text"> 
    image_4:<input name="image_4" type="text"> 
</form> 

<ul class="facebook_album_photo_list"> 
    <li alt="Paradise Vision from http://Stockwallpapers.in" title="Paradise Vision from http://Stockwallpapers.in" id="463526207001195"> 
     <a style="background: url(https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/427440_463526207001195_392636722_s.jpg) center top no-repeat;" class="overlay_photo" href="javascript:void(0);" onclick="add_image_fb('463526207001195');"></a> 
    </li> 
    <li alt="Anonymous Mask from http://Stockwallpapers.in" title="Anonymous Mask from http://Stockwallpapers.in" id="463151140372035"> 
     <a style="background: url(https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc6/10476_463151140372035_468769127_s.jpg) center top no-repeat;" class="overlay_photo" href="javascript:void(0);" onclick="add_image_fb('463151140372035');"></a> 
    </li> 
    <li alt="Mirana Nightshade Priestess of the Moon from http://Stockwallpapers.in" title="Mirana Nightshade Priestess of the Moon from http://Stockwallpapers.in" id="463137303706752"> 
     <a style="background: url(https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/482085_463137303706752_723444526_s.jpg) center top no-repeat;" class="overlay_photo" href="javascript:void(0);" onclick="add_image_fb('463137303706752');"></a> 
    </li> 
    <li alt="Fluid Flow in Lauterbrunnen from http://Stockwallpapers.in" title="Fluid Flow in Lauterbrunnen from http://Stockwallpapers.in" id="459694870717662"> 
     <a style="background: url(https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc7/312978_459694870717662_1068867909_s.jpg) center top no-repeat;" class="overlay_photo" href="javascript:void(0);" onclick="add_image_fb('459694870717662');"></a> 
    </li> 
</ul> 
+0

給我們更多的示例html。你給我們的是不夠的。有關如何佈置圖片的一些html會幫助我們。 – Daedalus

+0

@Daedalus添加了示例代碼 –

+0

您是否有每個圖像的輸入?如果我點擊4個不同的圖像並且只有3個輸入,會發生什麼?覆蓋其中之一? –

回答

2

由於onclick事件處理程序已經綁定到add_image_fb,只需添加以下內容:

function add_image_fb(id) { 
    $('.fb_upload_id input:text[value=""]').first().val(id); 
} 

更新:

function add_image_fb(id) { 
    var inputs=$(".fb_upload_id input:text[value='']"); 
    if(!inputs.length) alert('All input fields filled up!'); 
    else inputs.first().val(id); 
} 

Demo

+0

如何得到如果用戶選擇所有輸入字段...? –

+0

要查看用戶是否填充了所有輸入字段,則需要比較已填充字段的總數,即$('。fb_upload_id input:text')。length == $('。fb_upload_id input :文本[值= 「」!]')'。 –

+0

我只是想回答,但無論如何,你可以使用[this](http://jsfiddle.net/creC9/1/)。 –