java项目里面javascript打开页面时不执行,必须刷新一下才执行

zhaolh_78 2014-07-18 05:43:50
java项目,使用了SSH框架,projectsearch.jsp页面显示项目列表,提交后跳转到typeanalysis.jsp,显示项目下面的具体内容,typeanalysis.jsp里面使用ichartjs做了一个饼图,但是跳转之后,js脚本不执行,必须要刷新一下才能显示,尝试了很多方法,onload方法也使用了,即便写最简单的alert也不能执行
projectsearch.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>查询页面</title>
<link rel="stylesheet" href="css/jquery.mobile-1.3.0.min.css" />
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>

</head>
<body>
<form action="typeanalysis" method="get">
<div>
<label for="projectname">项目名称:</label>
<!--<input type="text" id="fid11" name="projectId" />-->
<select name="projectId">
<%
ArrayList<Object[]> arrayList1 = (ArrayList<Object[]>) request.getAttribute("list");
for (int i = 0; i < arrayList1.size(); i++) {
Object[] object1 = arrayList1.get(i);
String projectName = object1[0].toString(); //项目名称
String projectId = object1[1].toString(); //项目ID
%>
<option value="<%=projectId%>"><%=projectName%></option>
<%
}
%>
</select>
</div>

<footer>
<input type="submit" value="提交" />
</footer>
</form>
</body>
</html>

typeanalysis.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<html>
<head>
<title>户型分析图</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="css/jquery.mobile-1.3.0.min.css" />
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script src='js/ichart.latest.min.js'></script>

<script type='text/javascript'>
$(function(){
var chart = iChart.create({
render:"ichart-render",
width:800,
height:400,
background_color:"#f4f4f4",
gradient:false,
color_factor:0.2,
border:{
color:"#bcbcbc",
width:1
},
align:"center",
offsetx:0,
offsety:0,
sub_option:{
border:{
color:"#6d869f",
width:2
},
label:{
fontweight:500,
fontsize:18,
color:"#4572a7",
sign:"square",
sign_size:20,
border:{
color:"#BCBCBC",
width:0
},
background_color:"rgba(244,244,244,0)"
}
},
shadow:true,
shadow_color:"#666666",
shadow_blur:5,
showpercent:true,
column_width:"70%",
bar_height:"70%",
radius:"90%",
title:{
text:"户型分析图",
color:"#6d869f",
fontsize:20,
textAlign:"center",
font:"微软雅黑",
height:30,
offsetx:0,
offsety:0
},
subtitle:{
color:"#111111",
fontsize:16,
textAlign:"center",
font:"微软雅黑",
height:20,
offsetx:0,
offsety:0
},
footnote:{
color:"#111111",
fontsize:12,
textAlign:"right",
font:"微软雅黑",
height:20,
offsetx:0,
offsety:0
},
legend:{
enable:false,
background_color:"#fefefe",
color:"#333333",
fontsize:12,
border:{
color:"#BCBCBC",
width:1
},
column:1,
align:"right",
valign:"center",
offsetx:0,
offsety:0
},
coordinate:{
width:"80%",
height:"84%",
background_color:"#ffffff",
axis:{
color:"#a5acb8",
width:[1,"",1,""]
},
grid_color:"#d9d9d9",
label:{
fontweight:500,
color:"#666666",
fontsize:11
}
},
label:{
fontweight:500,
color:"#666666",
fontsize:11
},
type:"pie2d",
data:[

<%
ArrayList<Object[]> arrayList1 = (ArrayList<Object[]>) request.getAttribute("list");
for(int i=0;i<arrayList1.size();i++){
Object[] object1 = arrayList1.get(i);
String roomNum = object1[0].toString(); //房间数
String roomstatus = object1[1].toString(); //房间状态
String roomstruct = object1[2]!=null?object1[2].toString():""; //房间结构
String roomtype = roomstatus+roomstruct; //房间类型
String[] color = new String[] {"rgba(254,221,116,0.9)","rgba(130,216,239,0.9)","rgba(247,104,100,0.9)","rgba(128,189,145,0.9)","rgba(253,159,193,0.9)","rgba(130,221,193,0.9)"};
System.out.println(roomtype+"@@@@@@@@@"+roomNum+"&&&&&&&&&&&&"+color[i]);
%>
{
name:"<%=roomtype%>",
value:<%=roomNum%>,
color:"<%=color[i]%>"
}
<%
if(i!=arrayList1.size()-1){
%>,<%
}
}
%>

]
});
chart.draw();
});

</script>
</head>

<body>
<div id='ichart-render'> </div>
<script>function refelsh(){location.reload();}</script>
<button onClick="refelsh();" value="刷新">刷新</button>
</body>
</html>
...全文
756 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuanfeng6060 2015-12-28
  • 打赏
  • 举报
回复
这个问题怎么解决的啊?是不是跟<script src="js/jquery.mobile-1.3.0.min.js"></script>这个有关系,现在只能用ajax提交,然后跳转,感觉这样不好
skeibey 2014-12-09
  • 打赏
  • 举报
回复
解决了吗?我也遇到这个问题了。。。求助
ZhongGuanYao 2014-07-22
  • 打赏
  • 举报
回复
在<head></head>标签的<script></script>标签添加如下 $(document).ready(function(){ //这里直接添加生成图片的js }) 不要在<body>标签添加 <script>function refelsh(){location.reload();}</script> js不执行大多情况是js代码某地方出错了,仔细检查,一步步排除错误
ganaJJ 2014-07-22
  • 打赏
  • 举报
回复
用firefox浏览器调试,F12进入控制器,选择JS,看看是不是其他JS写错了
放纵的青春 2014-07-21
  • 打赏
  • 举报
回复
是不是js太大 第一次进去没加载完全啊? 看js的问题 我推荐火狐浏览器 很方便的
Ghost_520 2014-07-21
  • 打赏
  • 举报
回复
我觉得应该是你 js 代码出了问题吧, 打开 IE debugger 看看
qpc353386051 2014-07-19
  • 打赏
  • 举报
回复
如果页面使用JS比较多,特效也比较多,异步也用到了,可以考虑使用jQuery
zhaolh_78 2014-07-19
  • 打赏
  • 举报
回复
引用 7 楼 qpc353386051 的回复:
如果页面使用JS比较多,特效也比较多,异步也用到了,可以考虑使用jQuery
现在的问题是只要是js脚本就不执行,最简单的都不行
zhaolh_78 2014-07-18
  • 打赏
  • 举报
回复
引用 1 楼 Ghost_520 的回复:
你在body 的时候加上个 onload 试试,页面加载后, 执行 js 方法 <body onload="init()"> </body>
<body onload="javascript:alert('aaa')"> 这样写都不行,还是要刷新才能出来
wqc5461 2014-07-18
  • 打赏
  • 举报
回复
引用 3 楼 zhaolh_78 的回复:
[quote=引用 2 楼 wqc5461 的回复:] <body> <script> 要写在body里 </script> </body>
已经尝试过了,各种方法都试过了,还是不行[/quote] 用我这个方法写个 alert 试试能不能行,如果可以的话,就是jquery的加载问题。
zhaolh_78 2014-07-18
  • 打赏
  • 举报
回复
把这两个页面单独保存成静态页面,antion里面指定跳转是没有问题的
zhaolh_78 2014-07-18
  • 打赏
  • 举报
回复
引用 2 楼 wqc5461 的回复:
<body> <script> 要写在body里 </script> </body>
已经尝试过了,各种方法都试过了,还是不行
wqc5461 2014-07-18
  • 打赏
  • 举报
回复
<body> <script> 要写在body里 </script> </body>
Ghost_520 2014-07-18
  • 打赏
  • 举报
回复
你在body 的时候加上个 onload 试试,页面加载后, 执行 js 方法 <body onload="init()"> </body>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧