javascript - 如何防止自动完成选择模糊

标签 javascript jquery html

所以我正在编写这个在表格中显示 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/

相关文章:

javascript - Odoo POS javascript 变化

javascript - 循环对象数组中的属性的最有效方法是什么?

javascript - 循环无法正常工作

javascript - 将 JSON 对象存储到变量

javascript - 检测输入框中的粘贴

javascript - 将 dojoAttachpoint 关联到动态创建的 div?

jQuery 查找最近的元素

javascript - 在 Ajax 调用的 $.post 简写上切换加载程序

html - 兄弟选择器先出现的问题是什么?

html - 是否可以将带有 html 的 Markdown 文件转换为 pdf?