2015-04-02 130 views
0

这看起来像是重复的。但事实并非如此。将多个参数从jsp页面传递到javascript函数

这是我的代码:

<script language="JavaScript"> 
function popupwin(qid) 
{ 
    var myWindow = window.open("", "", "width=800, height=600"); 
    myWindow.document.write("<p> Qid = "+qid); 
} 
</script> 

....... 

<% 
try{ 
    Class.forName("oracle.jdbc.driver.OracleDriver"); 
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","Shravya17"); 
    ps=con.prepareStatement("select * from questions where category = ?"); 
    ps.setString(1,cat); 

    rs=ps.executeQuery(); 
    while(rs.next()){ 
     qid = rs.getInt(1); 
     ques = rs.getString(2); 
     cat = rs.getString(3); 
     a = rs.getString(4); 
     b = rs.getString(5); 
     c = rs.getString(6); 
     d = rs.getString(7); 
     ca = rs.getString(8); 
%>  
     <tr align = "center"> 
     <td> <%= qid %> </td> 
     <td> <%= ques %> </td> 
     <td> <%= cat %> </td> 
     <td> <%= a %> </td> 
     <td> <%= b %> </td> 
     <td> <%= c %> </td> 
     <td> <%= d %> </td> 
     <td> <%= ca %> </td> 
     <td>    
      <input type="submit" value="Edit" onclick=(popupwin(<%=qid%>));/> 
     </td> 
     </tr>   
<% 
    } 

这工作得很好。

但是,如何在函数调用中传递多个参数?

我试着传递由逗号分隔的参数,但它没有工作。

请帮忙!

回答

0

有没有理由不应该工作,我怀疑你有一个语法错误。尝试以下。

<td>    
    <input type="submit" value="Edit" onclick="(popupwin(<%=qid%>, 'test'))" /> 
</td> 

function popupwin(qid, testVal) { 
    console.log(testVal); // you should see 'test' in your browser's console 
} 
+0

原来我没有用双引号指定onclick的值。虽然我不知道我是如何错过它的。 谢谢! – Shravya 2015-04-02 12:56:38