原因:因为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>