2011-08-25 49 views
1

因此,我正在編碼此資產跟蹤器,顯示錶中的資產。當一個資產被簽出時,一個輸入字段將被填充到其中一列中,以指示誰對資產簽出進行了授權。此輸入框綁定到自動完成列表。當輸入字段丟失焦點時,框中的值應該成爲該單元的文本值,然後提交給數據庫。問題在於,在自動完成列表中單擊選擇時,它會接受用戶輸入的內容,而不是填寫選擇內容。我怎樣才能防止這種情況發生?如何防止模糊自動完成選擇

$(".checkOut").live('click', function() { 
     var $this = $(this), 
     $currentRow = $this.closest("tr"); 
     $currentRow 
      .removeClass("checkedIn") 
      .addClass("checkedOut"); 
     $this.replaceWith('<button title="Check In" class="checkIn" value="true" name="check_in"><img alt="Check In" src="../images/check.png"></button>'); 
     $status = "1"; 
     $timestamp = $.ajax({ 
      url: "time.php", 
      async: false 
     }).responseText; 
     $assetname = $currentRow.find("td:eq(0)").html();  
     $currentRow.find("td:eq(2)").html($who); 
     $currentRow.find("td:eq(3)").html($when); 
     $currentRow.find("td:eq(4)").html('<input type="text" id="auth" name="auth" value="" />'); 
     $auth = $currentRow.find("input"); 
     $auth.autocomplete("people.php").blur(function(event, ui) { 
      if(!$auth.val()) { 
       alert("Someone has to authorized this check out!"); 
       $auth.focus(); 
      } 
      else { 
       //accept input 
       $authby = $auth.val(); 
       $currentRow.find("td:eq(4)").text($authby); 
       //submit data 
       submitData($who,$when,$authby,$status,$assetname); 
      } 
     }); 
    }); 

在此先感謝。

回答

0

這是因爲你正在獲取文本框的值,例如 $ authby = $ auth.val();

你需要做的是,得到所選項目 $ authby = ui.item.value;

+0

另外,當您提交數據時,爲什麼不重複使用變量$ authby而不是執行$ auth.val()? submitData($誰,什麼時候,$ auth.val(),$地位,$ ASSETNAME); –