JSP程序是这样运行的: 先在服务器上运行,将结果传给客户端; JAVASCRIPT是这样运行的: 在客户端的浏览器解释执行;解决: JSP的变量: <% int b=9;%>function aa() { int a; a=<%=b%>; }数组也是一样的
javascript ,function里面可以用<%%>吗?我试了了,好像不行啊, 我不知道javacript里面能不能用下面这样子?function changedata(Index,strc){ var strc1[]=new Array(); int i; for (i=0;i<<%=cszstr.length%>;i++) strc1[i]=<%=cszstr[i]%>;老报错,找不到cszstr, 这个变量是在jsp里面定义的,也有值。 怎么回事?
首先cszstr应该定义为数组,你定义数组的时候已经指定了数组长度,所以就不需要用cszstr.length了,你这样用,本身就错了!应该是 : <% int RowCount;//数组长度 String ColumnName[]=new String[RowCount];//声明数组 for(int k=0;k<RowCount;k++) //给数组赋值 { ColumnName[k]="数组的值"; } %><script>function changedata() { var strc1[]=new Array(); int i; for (i=0;i<<%=RowCount%>;i++) { strc1[i]=<%=ColumnName[i]%>; } } </script>这就对了!试试吧!
To dragon_hgl(天涯)你那样可以吗? 循环变量i是在javascript中定义的,但是在jsp的数组中也用到了,这样可以吗? 应该是取不到值的吧,,
应该可以了 <% int i = 0; %> function changedata(Index,strc){ var strc1[]=new Array(); int i; for (i=0;i<<%=cszstr.length%>;i++) strc1[i]=<%=cszstr[i++]%>;
TO:sujianhua(我不懂)这样肯定还是不行的,你可以在IE中查看源文件。 这样更乱了,,
//调试通过 //////源文件 <html> <body> <% int i = 0; String cszstr[]={"1","2"}; %> <script language="javascirpt"> function changedata(Index,strc){ var strc1[]=new Array() ; int i ; <% for (i=0;i<cszstr.length;i++){ %> strc1[<%=i%>]=<%=cszstr[i]%>; <% } %> } </script> </body> </html>//运行后查看源文件 <html> <body><script language="javascirpt"> function changedata(Index,strc){ var strc1[]=new Array() ; int i ;strc1[0]=1;strc1[1]=2;} </script> </body> </html>
先在服务器上运行,将结果传给客户端;
JAVASCRIPT是这样运行的:
在客户端的浏览器解释执行;解决:
JSP的变量:
<% int b=9;%>function aa()
{
int a;
a=<%=b%>;
}数组也是一样的
我不知道javacript里面能不能用下面这样子?function changedata(Index,strc){
var strc1[]=new Array();
int i;
for (i=0;i<<%=cszstr.length%>;i++)
strc1[i]=<%=cszstr[i]%>;老报错,找不到cszstr,
这个变量是在jsp里面定义的,也有值。
怎么回事?
<%
int RowCount;//数组长度
String ColumnName[]=new String[RowCount];//声明数组
for(int k=0;k<RowCount;k++) //给数组赋值
{
ColumnName[k]="数组的值";
}
%><script>function changedata()
{
var strc1[]=new Array();
int i;
for (i=0;i<<%=RowCount%>;i++)
{
strc1[i]=<%=ColumnName[i]%>;
}
}
</script>这就对了!试试吧!
循环变量i是在javascript中定义的,但是在jsp的数组中也用到了,这样可以吗?
应该是取不到值的吧,,
也帮我看看我这个问题出在哪里?
代码如下:
<script language="JavaScript">
<!--
function checkps2(user_role){
if((user_role>996||form1.select_pswt.value=="无")&&(form1.ps_flag.value=="2"))
{
form1.submit();
}else
{ //检查评审问题!
window.alert("对不器!未置正式合同标记,或者此合同存在评审问题不能通过评审!");
form1.ps_flag.focus(); //将光标移至选择框!
}
}
-->
</script>
......
<input type="image" border="0" name="submittype5" src="../images/ps_save.bmp" onclick="checkps2(<%=user_role%>)">
......
请问我这样能行吗?
<%
int i = 0;
%>
function changedata(Index,strc){
var strc1[]=new Array();
int i;
for (i=0;i<<%=cszstr.length%>;i++)
strc1[i]=<%=cszstr[i++]%>;
这样更乱了,,
//////源文件
<html>
<body>
<%
int i = 0;
String cszstr[]={"1","2"};
%>
<script language="javascirpt">
function changedata(Index,strc){
var strc1[]=new Array() ;
int i ;
<%
for (i=0;i<cszstr.length;i++){
%>
strc1[<%=i%>]=<%=cszstr[i]%>;
<%
}
%>
}
</script>
</body>
</html>//运行后查看源文件
<html>
<body><script language="javascirpt">
function changedata(Index,strc){
var strc1[]=new Array() ;
int i ;strc1[0]=1;strc1[1]=2;}
</script>
</body>
</html>