Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
Jquery追加函数不工作?_Jquery_Append_Jquery Autocomplete - Fatal编程技术网

Jquery追加函数不工作?

Jquery追加函数不工作?,jquery,append,jquery-autocomplete,Jquery,Append,Jquery Autocomplete,这是我的工作代码,直到得到表格格式的自动完成列表。但是如何用append函数给出标题呢 <script type="text/javascript"> function pageLoad(sender, args) { $(function () { $("#<%=txt.ClientID %>").autocomplete({ source: function (request, response) {

这是我的工作代码,直到得到表格格式的自动完成列表。但是如何用append函数给出标题呢

<script type="text/javascript">

function pageLoad(sender, args) {
    $(function () {
        $("#<%=txt.ClientID %>").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '<%=ResolveUrl("~/Webservice.asmx/GetDetails") %>',
                    data: "{ 'prefix': '" + request.term + "'}",
                    dataType: "json",
                    type: "POST",
                    async: false,
                    mustMatch: true,
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.split('^')[0],
                                val: item.split('^')[1]
                            }
                        }))
                    },
                    error: function (response) {

                    },
                    failure: function (response) {

                    }
                });
            },
            select: function (e, i) {
                $("#<%=hdnC.ClientID %>").val(i.item.val);
                if (i.item.val == "No Records Found") {
                    $("#<%=hdnC.ClientID %>").val(-1);
                    document.getElementById('<%=txt.ClientID%>').value = "";
                    return false;
                }

            },
            minLength: 0
        }).bind('focus', function () { $(this).autocomplete("search"); })
        .data("autocomplete")._renderItem = function(ul, item) {
            return $("<li></li>").data("item.autocomplete", item).append("<a><table><tr><td width='200px'>" + item.label + "</td>" + "<td>" + item.val.split('~')[6] + "</td></tr></table></a>").appendTo(ul);


         };
    });
}

函数页面加载(发送方,参数){
$(函数(){
$(“#”)自动完成({
来源:功能(请求、响应){
$.ajax({
url:“”,
数据:“{'前缀':'”+request.term+“}”,
数据类型:“json”,
类型:“POST”,
async:false,
mustMatch:是的,
contentType:“应用程序/json;字符集=utf-8”,
成功:功能(数据){
响应($.map)(数据.d,函数(项){
返回{
标签:item.split('^')[0],
val:item.split('^')[1]
}
}))
},
错误:函数(响应){
},
故障:功能(响应){
}
});
},
选择:功能(e,i){
$(“#”)val(i.item.val);
如果(i.item.val==“未找到记录”){
$(“#”)val(-1);
document.getElementById(“”).value=“”;
返回false;
}
},
最小长度:0
}).bind('focus',function(){$(this).autocomplete(“search”);})
.数据(“自动完成”)。\u renderItem=功能(ul,项目){
返回$(“
  • ”).data(“item.autocomplete”,item.append”(“+item.label++”+item.val.split(“~”)[6]+”).appendTo(ul); }; }); }

    自定义jquery自动完成功能的完美示例

    $(document).ready(function(){
      $("#birds").autocomplete({
        source: "birds/get_birds" // name of controller followed by function
      }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
            var inner_html = '<a><div class="list_item_container"><div class="image"><img src="img/' + item.image + '"></div><div class="label">' + item.label + '</div><div class="description">' + item.description + '</div></div></a>';
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append(inner_html)
                .appendTo( ul );
        };
    });
    
    $(文档).ready(函数(){
    $(“#鸟”).autocomplete({
    来源:“birds/get_birds”//控制器名称,后跟函数
    }).data(“ui自动完成”)。\u renderItem=功能(ul,项目){
    
    var internal_html='

    Width=200px是无效的html…是否需要在
    Width='200px'
    周围添加引号?@roydukkey否它应该没有px Width=“200”它不应该是像素。c-link是正确的。看到这个@Milindantwar w3schools是傻瓜…谢谢你的回复,但它不符合我的要求。你能帮我以表格格式显示数据吗?@VinetKadkol@sona你能告诉我你需要什么格式的吗?我已经得到了解决方案,但我想在表格中加标题。你能不能帮助我在这里更新我的最新代码。@vineet Kadkol