0

我有一个动态表单......它有一个类似的输入字段

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

我还有一个 ul li 块,它从 Facebook 相册中获取图像......当我们点击图像时,它的“id”必须填写任何输入字段的空,并且没有重复选择......

图片:查看此图片可能有助于理解

编辑:

<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>
4

1 回答 1

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);
}

演示

于 2012-09-09T03:50:51.197 回答