动态绑定autocomplete模糊查询

1.在控件的onfocus绑定,些方法绑定,如果多次点击,会绑定多次autocomplete,查询时会执行多次查询。 

<input type="text" name="FEE_NM" class="text_input" style="width: 100%;" value="" onfocus="autoFeetyp(this,150)"/>
<input type="text" name="FEE_TYP" value="" />	

/**
	 * 给控件注册费用类型
	 * @param obj
	 * @param width
	 * @param callBack
	 */
	function autoFeetyp(obj,width, callBack){
		var url = Systempath+"/AutoSuggestServlet?type=feetype&filter=ocode ='OTHERS'&match=true&time=" + Math.round(Math.random() * 10000);
		url = encodeURI(encodeURI(url));
		$(obj).autocomplete(url, {
			multiple : false,
			autoFill : false,
			mustMatch : false,
			matchContains : true,
			dataType : 'json',
			parse : parseFn,
			width : width,
			scroll : true,
			scrollHeight : 200,
			cacheLength : 1000,
			matchSubset : true,//只有cacheLength>1时有效
			formatItem : function(row, i, max) {
				return row.cname;
			}
		}).result(function(event, item, formatted) {//把返回的结果内容显示在其他文本框上
			$(this).val(item.cname);
			$(this).next().val(item.code);
			if (typeof(callBack) == "function") {
				callBack (this);
			}
		});
	}

2.每次绑定autocomplete时,先删除掉原来的input,再重新增加一个新的input,这样可避免在同一个input上绑定多次autocomplete的问题.

    //动态绑定jquery.autocomplete
	function nature_onchange(obj) {
		//动态获取过滤条件
		var filter = "";
		var nature = $("#nature").val();
		if (nature){
			filter = "nature='"+nature+"'";
		}
		//先删除掉原来的input,再重新增加一个新的input,这样可避免在同一个input上绑定多次autocomplete的问题
	    var portLoad = "<input type=\"text\" onpropertychange=\"writeValue(this,'portLoad');\" id=\"shippingline1\" name=\"shippingline1\" class=\"text_input\" style=\"width: 90%;\"/>"
	              +"<input type=\"text\" id=\"portLoad\" name=\"portLoad\" />";
		$("#shippingline1_td").html(portLoad);
		autoSuggest($("#shippingline1"),150,null,"shippingline1",filter);

		var portUnload = "<input type=\"text\" onpropertychange=\"writeValue(this,'portUnload');\" id=\"shippingline2\" name=\"shippingline2\" class=\"text_input\" style=\"width: 90%;\"/>"
				+"<input type=\"text\" id=\"portUnload\" name=\"portUnload\" />";
		$("#shippingline2_td").html(portUnload);
		autoSuggest($("#shippingline2"),150,null,"shippingline2",filter);
	}


	/**
	 * 给控件注册模糊查询
	 * @param obj
	 * @param width
	 * @param callBack
	 */
	function autoSuggest(obj,width, callBack,type,filter){
		var url = Systempath+"/AutoSuggestServlet?type="+type+"&filter="+filter+"&match=true&time=" + Math.round(Math.random() * 10000);
		url = encodeURI(encodeURI(url));
		$(obj).autocomplete(url, {
			multiple : false,
			autoFill : false,
			mustMatch : false,
			matchContains : true,
			dataType : 'json',
			parse : parseFn,
			width : width,
			scroll : true,
			scrollHeight : 200,
			cacheLength : 1,
			matchSubset : false,//只有cacheLength>1时有效
			formatItem : function(row, i, max) {
				return row.cname;
			}
		}).result(function(event, item, formatted) {//把返回的结果内容显示在其他文本框上
			$(this).val(item.cname);
			$(this).next().val(item.code);
			if (typeof(callBack) == "function") {
				callBack (this);
			}
		});
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值