所以我正在编写这个在表格中显示 Assets 的 Assets 跟踪器。 checkout Assets 时,其中一列中会填充一个输入字段,以指示谁授权了 Assets checkout 。该输入框绑定(bind)到自动完成列表。当输入字段失去焦点时,框中的值应成为该单元格的文本值,然后提交到数据库。问题是,当在自动完成列表中单击某个选项时,它会接受用户输入的内容,而不是填写该选项。我怎样才能防止这种情况发生?
$(".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);
}
});
});
提前致谢。
最佳答案
这是因为您正在获取文本框的值,即 $authby = $auth.val();
您需要做的是,获取所选项目 $authby = ui.item.value;
关于javascript - 如何防止自动完成选择模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7195901/