簡體   English   中英

HTML單選按鈕數組

[英]Array of HTML radio button

我有一個add contact form其中包含動態添加的單選按鈕和聯系人信息的輸入字段:

<tr>
<td><input class="case" type="checkbox"/></td>
<td style="text-align: center"><input type="radio" value="1"  name="contact[principal][]" id="contact_1" class="icheck" @if( $contact->principal == 1) checked @endif>                                                                    </td>
<td><input type="text" value="{{ $contact->name }}" data-type="ItemName" name="contact[name][]" id="name_1" class="form-control autocomplete_txt" autocomplete="off"></td>
<td><input type="text" value="{{ $contact->position }}" name="contact[position][]" id="position_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
<td><input type="text" value="{{ $contact->phone }}" data-mask="phone-ext" name="contact[phone][]" id="tel_1" class="form-control changesNo" autocomplete="off"  ondrop="return false;" onpaste="return false;"></td>
<td><input type="email" value="{{ $contact->email }}" name="contact[email][]" id="email_1" class="form-control changesNo" autocomplete="off"  ondrop="return false;" onpaste="return false;"></td>
</tr>

這是一個: https : //jsfiddle.net/66y6dtx0/

只能由一位聯系人擔任負責人,這是我從POST收到的示例:

[contact] => Array
    (
        [name] => Array
            (
                [0] => Jane Emerson
                [1] => Jhon Doe
            )

        [position] => Array
            (
                [0] => Gerente
                [1] => CEO
            )

        [phone] => Array
            (
                [0] => (888) 878-3969
                [1] => (888) 578-8919
            )

        [email] => Array
            (
                [0] => jhon.e@gmail.com
                [1] => jhon@example.org
            )

        [principal] => Array
            (
                [0] => 1
            )

    )

問題是,當有多個聯系人時,索引與被選為主要聯系人的索引不匹配。

我怎樣才能解決這個問題?

我使用Laravel框架是有幫助的。

我對這個問題的解決方案:

我在這篇文章的幫助下將使用jquery的行索引添加到了單選按鈕的名稱中,並使用jquery取消了對其他單選按鈕的選擇:

廣播不同的名稱-僅選中一個

我仍然好奇是否有更好的解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM