设置 autocomplete 只能选择下拉框的内容

$.fn.extend({
  authorizeditemlist: function(options) {
   return this.each(function() {
    var sender = $(this);
    var url = "search.asp";
    sender.unautocomplete()
    .autocomplete(url, {
     max: 0
     ,mustMatch:true
     ,minChars: 0
     ,width: 180
     ,matchContains: "word"
     ,autoFill: false
     ,extraParams: {
      regionid: sender.closest("table").find("select[name=id]").val()
     }
     ,formatItem: function(row){return row[1];}
     ,formatResult: function(row){return row[1];}

    })
    .result(function(event, data, formatted) {
     var tr = $(this).closest("tr");
     if(data) tr.find("input[name=id]").val(data[0]);  //不加此判断会报错:data[0]为null
    });
   });
  }
 });

posted @ 2012-09-14 18:22  y0umer  阅读(621)  评论(0编辑  收藏  举报