Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在jquery自动完成中获取textbox的值_Javascript_Jquery_Jquery Ui_Jquery Ui Autocomplete - Fatal编程技术网

Javascript 无法在jquery自动完成中获取textbox的值

Javascript 无法在jquery自动完成中获取textbox的值,javascript,jquery,jquery-ui,jquery-ui-autocomplete,Javascript,Jquery,Jquery Ui,Jquery Ui Autocomplete,我正在使用jquery1.9.1.js和jquery-ui-1.10.3.custom.min.js。我在IE9浏览器上运行时出现错误“无法获取属性'toLowerCase'的值”:对象为null或未定义“。下面是我的代码 $("input[id^='TextBoxAssociate']").autocomplete( { source: function (request, response) { $.ajax({

我正在使用
jquery1.9.1.js
jquery-ui-1.10.3.custom.min.js
。我在IE9浏览器上运行时出现错误
“无法获取属性'toLowerCase'的值”:对象为null或未定义“
。下面是我的代码

  $("input[id^='TextBoxAssociate']").autocomplete(
        {
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "CreateEditRequest.aspx/GetEmpNames",
                    data: "{'empName':'" + $(this).val() + "'}",
                    dataType: "json",
                    success: function (data) {
                        response($.map(data.d, function (el) {
                            return {
                                label: el.EmpName,
                                value: el.EmpId
                            };
                        }));
                    },
                    error: function (result) {
                        alert("Error");
                    }
                });
            }
当我注释
response($.map(data.d,function(el){…}
part)时,没有错误,也没有输出。版本控制或浏览器兼容性可能有问题。我也在ie8中尝试过。也可以通过添加

<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
在上,
this
将不包含对相关
输入的引用。它可能包含对新创建函数的引用,但这是未记录的

要实现您的目标,您有两个选择:

如果您只想在输入上键入文本 然后,使用
request.term
(它是一个字符串):


在这种方法中,其他jQuery函数,如
.attr()
和else,将像往常一样可用于
myElement

标题中的错误不会出现在您发布的代码中的任何地方(您不调用toLowerCase)。您可以发布响应函数的代码或javascript调试器报告的错误位置吗?来自
CreateEditRequest.aspx/GetEmpNames?empName=John
?@acdcjunior:这给了我一个错误
Microsoft JScript运行时错误:“$”未定义
Oh,然后将其更改为:
数据:“{empName”:”+request.term+“}”,
太好了!我将添加它作为答案,以便其他人将来可以解决相同的问题,好吗?太好了,这正是我想要的。谢谢@acdcjunior!我一直在寻找这样的选项。你让我开心了:)
val: function( value ) {
    var ret, hooks, isFunction,
        elem = this[0];
    if ( !arguments.length ) {
        if ( elem ) {
            hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];

            if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
                return ret;
            }
            ret = elem.value;
            return typeof ret === "string" ?
                // handle most common string cases
                ret.replace(rreturn, "") :
                // handle cases where value is null/undef or number
                ret == null ? "" : ret;
        }

        return;
    }
$("input[id^='TextBoxAssociate']").autocomplete({
    source: function (request, response) {
        $.ajax({
            // ...
            data: "{'empName':'" + request.term + "'}", // <--------------------
            // ...
        });
    });
$("input[id^='TextBoxAssociate']").each(function () {
    var myElement = $(this);
    myElement.autocomplete({
    source: function (request, response) {
        $.ajax({
            // ...
            data: "{'empName':'" + myElement.val() + "'}", // <-----------------
            // ...
        });
    }
});