0

我有以下 jquery 移动脚本,用于为两个文本字段customerstore.

$(function() {
    $("#customer").keyup(function(event) {
            if(document.getElementById("customer").value == "")
                $( "#store" ).prop( 'disabled', true );
    });

    $('#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 );
            $("#store").removeAttr("disabled").focus();
            return false;
        }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      $(ul).attr('data-role', 'listview');
      $(ul).listview();
      return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
    };

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

});

这是html:

<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=""/>
<input type="hidden" id="store-id" />
<p id="store-description"></p>

客户文本框的自动完成功能正在工作,但不适用于商店文本字段。我在商店自动完成中复制了相同的customer自动完成代码,我确信数据是从 SearchStore.php 返回的。

任何解决此问题的建议将不胜感激。

4

1 回答 1

0

你可以试试下面的代码:

 $(function() {
    $("#customer").keyup(function(event) {
            if(document.getElementById("customer").value == "")
                $( "#store" ).prop( 'disabled', true );
    });

    $('#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 );
            $("#store").removeAttr("disabled").focus();
            return false;
        }
    })

.each(function() {
    $(this).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      $(ul).attr('data-role', 'listview');
      $(ul).listview();
      return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
    };
    }

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

});
于 2013-08-05T12:19:07.300 回答