简体   繁体   English

在javascript网址中传递参数

[英]pass the parameter in javascript url

I want to pass the parameter value in url.I have the parameter 'redir'.redir value is changed dynamically as 1,2,3,4,5,... or any number I passed the redir value from php.I passed the value to the newpage() function. 我想在url中传递参数值。我有参数'redir'.redir值动态更改为1,2,3,4,5,...或我从php传递redir值的任何数字。 newpage()函数的值。 I want to pass dynamic redir value as in rec_resume_post.php?req_id=1 or rec_resume_post.php?req_id=2. 我想传递动态redir值,如rec_resume_post.php?req_id = 1或rec_resume_post.php?req_id = 2。

<?php
 echo '<tr><td>'.$title.'</td><td>'.$c_name.'</td><td>'.$e_first_name.'</td><td>'.$num.'</td><td><input type="submit" value="submit" onClick="newpage('.$req_id.');" /></td></tr>'; 
?>
 <script>
   function newpage(redir){
    window.alert(redir);
    window.open("rec_resume_post.php?req_id=redir");
      }

Try like this: 尝试这样:

window.open("rec_resume_post.php?req_id=" + redir);

So it would be like this: 所以会像这样:

<?php
 echo '<tr><td>'.$title.'</td><td>'.$c_name.'</td><td>'.$e_first_name.'</td><td>'.$num.'</td><td><input type="submit" value="submit" onClick="newpage('.$req_id.');" /></td></tr>'; 
?>
 <script>
   function newpage(redir){
    window.alert(redir);
    window.open("rec_resume_post.php?req_id"+ redir);
      }

Add the variable to the string. 将变量添加到字符串。

<?php
 echo '<tr><td>'.$title.'</td><td>'.$c_name.'</td><td>'.$e_first_name.'</td><td>'.$num.'</td><td><input type="submit" value="submit" onClick="newpage('.$req_id.');" /></td></tr>'; 
?>
 <script>
   function newpage(redir){
    window.alert(redir);
    window.open("rec_resume_post.php?req_id"+ redir);
      }

Edited: Suggested the join method for combining strings. 编辑:建议使用合并字符串的连接方法。 But as Rahul pointed out below, using + is the best way to combine strings. 但是正如Rahul在下面指出的那样,使用+是组合字符串的最佳方法。

您需要像这样连接字符串:

window.open("rec_resume_post.php?req_id="+redir);

更改window.open行,如下所示:

window.open("rec_resume_post.php?req_id=" + redir);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM