在jsp页面中包含外部Java脚本文件 [英] include external java script file in jsp page
本文介绍了在jsp页面中包含外部Java脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为pageing.js的外部JavaScript文件.以下是文件的内容:
I have an external JavaScript file named paging.js. Following are the contents of the file:
function Pager(tableName,itemPerPage){
this.tableName = tableName;
this.itemPerPage = itemPerPage;
this.currentPage = 1;
this.pages = 0;
this.init()= function(){
alert("init called ");
var rows = document.getElementById(tableName).rows;
var records = (rows.length - 1);
this.pages = Math.ceil(records / itemPerPage);
}
this.showPageNav = function(pagerName,positionId){
alert("show page navi call");
var element = document.getElementById(positionId);
var pagerHtml = '<input src = "next.jpg" type="image">';
pagerHtml += '<input src = "next.jpg" type="image">' ;
element.innerHTML = pagerHtml;
}
}
现在,我尝试从jsp页面调用init,例如.
Now I tried to call init from my jsp page like .
<script type="text/javascript">
var pager = new Pager('results',7);
pager.init();
</script>
此代码是我在完成我的jsp页面中的正文部分之前输入的.
This code i put before complete my body part in my jsp page.
为包含此页面,我在行中添加了
For including this page I put line like
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/paging.js"></script>
但是我无法调用init方法.有谁可以帮助我发现问题?
But i can't able to call init method. Is there anyone to help me for finding problem?
推荐答案
这行代码就是问题所在:
This line of code is the problem:
this.init()= function(){
将其更改为:
this.init=function() {
这篇关于在jsp页面中包含外部Java脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文