如何将变量作为参数传递给javascript函数(How to pass a variable as a argument to javascript function)

编程入门 行业动态 更新时间:2024-10-22 07:31:36
如何将变量作为参数传递给javascript函数(How to pass a variable as a argument to javascript function)

我的jsp页面中有一个变量,我希望将其作为参数传递给javascript函数。如何做?

码:-

<% String ts=request.getParameter("testname"); session.setAttribute("tname", ts); Connection con=null; Statement s=null; ResultSet r=null; int t=60000; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:online_testing"); s=con.createStatement(); r=s.executeQuery("select * from "+ts+""); String time=r.getString("duration"); t=Integer.parseInt(time)*60000; } catch(Exception e1) { response.setContentType("text/html"); out.println(e1.toString()); } %> <body onload="setTimeout('submitForm()',<%=t%>)">

它只取t的初始值,而不是更新的值。 如何将函数setTimeout()中的变量“t”的值作为参数传递?

I have a variable in my jsp page which i want to pass as an argument to a javascript function.How to do it?

code:-

<% String ts=request.getParameter("testname"); session.setAttribute("tname", ts); Connection con=null; Statement s=null; ResultSet r=null; int t=60000; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:online_testing"); s=con.createStatement(); r=s.executeQuery("select * from "+ts+""); String time=r.getString("duration"); t=Integer.parseInt(time)*60000; } catch(Exception e1) { response.setContentType("text/html"); out.println(e1.toString()); } %> <body onload="setTimeout('submitForm()',<%=t%>)">

It is taking only the initial value of t,not the updated one. How can I pass the value of variable "t" in function setTimeout() as an argument?

最满意答案

修改您的代码如下

<% int i=1; %> <form name="ifrm" onsubmit="return validateform('<%=i%>')" action="Givetest" method="post"> //code </form>

Modify your code as below

<% int i=1; %> <form name="ifrm" onsubmit="return validateform('<%=i%>')" action="Givetest" method="post"> //code </form>

更多推荐

ts,<%,setTimeout,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-07-04 17:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   如何将   函数   参数   argument

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!