1

2 つのテキスト フィールドがあります (オートコンプリート機能付き)。

<label for="name">Customer:</label>
<input type="text" name="customer" id="customer" value=""  />
<input type="hidden" id="customer-id" />
<p id="customer-description"></p>


<label for="name">Store:</label>
<input type="text" name="store" id="store" value=""  disabled="true" />
<input type="hidden" id="store-id" />
<p id="store-description"></p>

ご覧のとおり、最初は 2 番目のテキストフィールドを無効にしました。私が望むのは、ユーザーが顧客のテキストボックスからアイテムを選択したときに、ストアのテキストボックスが有効になることです。これは私が試したものですが、ストアフィールドを有効にしません:

$(function() {
    $('#customer').autocomplete({
        source: "./SearchCustomer.php?term="+document.getElementById("customer").value,
        minLength: 0,
        focus: function( event, ui ) {
            $( "#customer" ).val( ui.item.label );
            return false;
        },
        select: function (event, ui) {
            $( "#customer" ).val( ui.item.label );
            $( "#customer-id" ).val( ui.item.value );
            return false;
        }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
    };
    $("#store").removeAttr("disabled").focus();
});

あなたの助けに感謝します。

4

2 に答える 2

1

select 関数に追加$('#store').prop('disabled', false).focus();します。

select: function(ev, ui) {
    $( "#customer" ).val( ui.item.label );
    $( "#customer-id" ).val( ui.item.value );
    $( "#store" ).prop( 'disabled', false ).focus();
    return false;
}

そのため、オートコンプリート アイテムが選択されている場合は、無効なプロパティ#storeを false に設定し、要素にフォーカスを与えます。

ここにフィドルがあります

于 2013-08-05T09:30:40.593 に答える