2011-05-03 92 views
-2

我有一段jQuery代码为这是工作在普通的HTML页面,但在JSP页面不能在这里工作动画不工作是我的代码jQuery代码在JSP页面

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script> 
<script src="http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js" type="text/javascript"></script> 
<script> 
    $('#totalCost1').stop().animate({ backgroundColor: '#ffe000' }, 250).animate({ backgroundColor: '#f0f0f0'}, 750); 
    $('#coop1').stop().animate({ backgroundColor: '#ffe000' }, 250).animate({ backgroundColor: '#f0f0f0'}, 750); 
    $('#outOfPocket1').stop().animate({ backgroundColor: '#ffe000' }, 250).animate({ backgroundColor: '#f0f0f0'}, 750); 
</script> 
+4

*不*工作是不是非常有帮助。不工作如何?错误?意外的结果? – alex 2011-05-03 12:21:23

+3

九个月* 24个其他问题*。有鉴于此,您现在应该可以对代码进行格式化。 @alex为你修正了第一个版本,但你最近的修改再次打破了它。查看问题编辑区域右侧的方便**如何格式化**框,以及上面** [?] **中的[链接页面](http://stackoverflow.com/editing-help)问题领域。 – 2011-05-03 12:29:29

回答

2

您的JS代码必须在<script></script>标签

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script> 
<script src="http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js" type="text/javascript"> 
$('#totalCost1').stop().animate({ backgroundColor: '#ffe000' }, 250).animate({ backgroundColor: '#f0f0f0'}, 750); 
     $('#coop1').stop().animate({ backgroundColor: '#ffe000' }, 250).animate({ backgroundColor: '#f0f0f0'}, 750); 
     $('#outOfPocket1').stop().animate({ backgroundColor: '#ffe000' }, 250).animate({ backgroundColor: '#f0f0f0'}, 750);</script> 
+3

你不能像这样在'script'元素中有'src' **和**内容。你必须有单独的脚本元素:http://www.w3.org/TR/html5/scripting-1.html#script(这不仅仅是学术性的,它实际上不适用于某些主流浏览器。 )(除此之外,假设脚本事件不仅仅是问题中的错误,很好的捕获。) – 2011-05-03 12:25:21

+0

对不起,忘了粘贴其余代码 – prakashkadakol 2011-05-03 12:26:11

+0

显然,这只是一个错误,OP现在已经修复。 – 2011-05-03 12:36:22

2

下面应该工作。 如果您有jQuery脚本在:

/MyApp/WebContent/scripts/jquery-1.6.2.js

您需要任何JSP/FTL参考如下: 如果是JSP于:

/MyApp/WebContent/pages/user/listUsers.jsp

在JSP参阅样式表作为:

<link rel="stylesheet" type="text/css" href="/myapp/styles/myStyle.css"/> 

在JSP参考JQuery的是:

<script type="text/javascript" src="/myapp/scripts/jquery-1.6.2.js"></script>