jquery-1.2.6.js与json.js以及处理ajax框架的prototype.js同时引入到jsp页面时,在引用jquery.js中的方法时会有冲突,必须按先后序顺引入这些文件。 最先引入json.js文件,然后引入prototype.js文件,最后引入jquery-1.2.6文件,如果先引入的jquery文件则会报错“找不到对象或对象不存在”。 例如: <script language="javascript" type="text/javascript" src="<%=basePath%>/include/scripts/json2.js"></script> <script language="javascript" type="text/javascript" src="<%=basePath%>/include/scripts/prototype.js"></script> <script language="javascript" type="text/javascript" src="<%=basePath%>/include/scripts/jquery-1.2.6"></script>
这样就不会有问题,这个问题找了好长时间才发现的,先是从代码上找,然后写最简单的代码测试,最后怀疑是不是引入了js文件的问题,结果找到了上面的原因。
参考例子:
<jsp:include page="../cssInclude.jsp" flush="true" />
<script src="javascript/validate/prototype_for_validation.js" type="text/javascript"></script>
<script src="javascript/validate/tooltips.js" type="text/javascript"></script>
<script src="javascript/validate/validation_cn.js" type="text/javascript"></script>
<link rel="stylesheet" href="templates/${layout}/css/skin.css" type="text/css">
<script type="text/javascript" src="javascript/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="javascript/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="javascript/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="javascript/jquery.blockUI.js"></script>
<script type="text/javascript" src="javascript/utilForCustom.js"></script>
<script type="text/javascript" src="javascript/jquery.jgrowl_minimized.js"></script>
<script type="text/javascript" src="javascript/jmesa/jquery.jmesa.min.js"></script>
<script type="text/javascript" src="javascript/jmesa/jmesa.min.js"></script>
<script type="text/javascript" src="javascript/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="javascript/jquery.cookie.js"></script>
<script type="text/javascript" src="javascript/jquery.json.js"></script>
<script type="text/javascript" src="javascript/common_ui.js"></script>