2015-04-02 138 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

相關問題