使用不同参数的jquery函数分别调用同一个js函数,传到后台的参数却一样

原因:因为jquery函数和被调用函数在同一个<javaScript>标签中

解决办法:将jquery函数和被调用js函数放到不同的javaScript标签,问题就没有了

<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"></script> 
	<script type="text/javascript">
		<!-- 使用ajax加载数据字典,生成select
			//参数1:数据字典类型(dict_type_code)
			//参数2:将下拉选加入的标签id
			//参数3:生成下拉选时,select标签的name属性值
			//参数4:需要数据回显时,选中哪个option
		-->
	function loadSelect(typecode,positionId,selectname,selectedId){
	//1 创建select对象,将name属性指定
	var $select =  $("<select name="+selectname+" ></select>");
	//2 添加提示选项
	$select.append($("<option value='' >---请选择---</option>"));
	//3 使用jquery 的ajax 方法,访问后台Action
	$.post("${pageContext.request.contextPath}/BaseDictAction", { dict_type_code:typecode},
	  function(data){
	   		//遍历
	//4 返回json数组对象,对其遍历
	   		$.each( data, function(i, json){
		// 每次遍历创建一个option对象
	   			var $option = $("<option value='"+json['dict_id']+"' >"+json["dict_item_name"]+"</option>"); 
	   			
			if(json['dict_id'] == selectedId){
			//判断是否需要回显 ,如果需要使其被选中
				$option.attr("selected","selected");
			}
		//并添加到select对象
				$select.append($option);
	   		});
	  },"json");
		
	//5 将组装好的select对象放入页面指定位置
	$("#"+positionId).append($select);
}
	</script>
	<script>
		$(document).ready(function(){
			loadSelect("006","level","cust_level.dict_id" <s:if test="#customer.cust_level!=null">,<s:property value="#customer.cust_level.dict_id" /></s:if>);
			loadSelect("001","industry","cust_industry.dict_id" <s:if test="#customer.cust_industry!=null">,<s:property value="#customer.cust_industry.dict_id" /></s:if>);
			loadSelect("009","source","cust_source.dict_id" <s:if test="#customer.cust_source!=null">,<s:property value="#customer.cust_source.dict_id" /></s:if>);
	
	
	});
	</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值