简体   繁体   English

Javascript帮助通过URL传递数据

[英]Javascript Help Passing Data via URL

Hi I wonder if someone could help me with this small issue I have the following code which I need to modify. 嗨,我想知道是否有人可以帮助我解决这个小问题,所以我有以下代码需要修改。

<script type="text/javascript">
function code(id) {
  $('#myStyle').load('myphp.php?id=' + id);
}
</script>

I need to pass another variable into this code and add it to the GET part of the URL for example above it will include the URL myphp.php?id=124545 我需要将另一个变量传递到此代码中,并将其添加到URL的GET部分,例如,在上面的示例中,它将包含URL myphp.php?id = 124545

I want to add a second variable called num to the URL part but am confused what the code will need to become to make the correct post via GET 我想在URL部分添加一个名为num的第二个变量,但对于通过GET进行正确发布所需的代码感到困惑

<script type="text/javascript">
function code(id,num) {
  $('#myStyle').load('myphp.php?id=' + id); // how do I add the &num=124 for example
} 
</script>

Thanks in advance 提前致谢

Simple. 简单。 Use: $('#myStyle').load('myphp.php?id=' + id + '&num=' + num); 使用: $('#myStyle').load('myphp.php?id=' + id + '&num=' + num);

Reference: http://www.quirksmode.org/js/strings.html#conc 参考: http : //www.quirksmode.org/js/strings.html#conc

Hope it helps! 希望能帮助到你!

Concatenate "&num="+num onto the string you already have: "&num="+num连接到您已经拥有的字符串上:

<script type="text/javascript">
function code(id,num) {
  $('#myStyle').load('myphp.php?id=' + id  + "&num=" + num); // how do I add the &num=124 for example
} 
</script>

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

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