keyup 事件仅从第一个输入中获取值,其中 table 中有多个输入具有相同的名称和 ID

keyup event only gets value from first input where multiple are available in a table with same name and id

这是输入框

<input name ="norvic_id" id="norvic_id" type="text" class="form-control" placeholder="Norvic ID">

这是脚本

<script>
    $('#norvic_id').keyup(function() {
            var x = $('input[name=norvic_id]').val();
            $("#nid").val(x);
    });
</script>

nid 是我从 norvic_id 字段

发送数据的表单中的隐藏输入值
{!!Form::open(['method'=>'POST','route'=>['newpatients.store'], 'class'=>'form-horizontal
                                bordered-row','enctype'=>'multipart/form-data'])!!}
                                <input name ="nid" id="nid" type="hidden" value="" class="form-control">
                                <input name ="pid" id="pid" type="hidden" value="{{$d->id}}" class="form-control">
                                <button type="submit" class="btn btn-sm btn-sm btn-success btn_glyph" id="confirm">Confirm</button>
                            {!!Form::close() !!}

ID在所有网站中必须是唯一的。

您可以为该输入设置 norvic_id class:

然后在jQuery中使用class选择器:

$('.norvic_id').keyup(function() {
    var x = $(this).val();
    $("#nid").val(x);
});