Javascript范围和顺序性问题

Javascript范围和顺序性问题,javascript,php,jquery,asynchronous,Javascript,Php,Jquery,Asynchronous,我想从查询中获取一个id,并将其显示在html中 我希望将内容保存在单独的javascript文件中,因为将来,它将从php检索json,并根据一些复选框、单选按钮等对其进行过滤,然后显示结果 在这一刻,我得到了一个空白页,id值没有显示,所以我做错了什么 http://localhost:10600/js1/index.php?id=5 index.php <html> <head> <script type='text/javascript' src='htt

我想从查询中获取一个id,并将其显示在html中

我希望将内容保存在单独的javascript文件中,因为将来,它将从php检索json,并根据一些复选框、单选按钮等对其进行过滤,然后显示结果

在这一刻,我得到了一个空白页,id值没有显示,所以我做错了什么

http://localhost:10600/js1/index.php?id=5
index.php

<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
</head>
    <body>
        <div class="results"></div>
    </body>
</html>

<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="display.js"></script>
<script type="text/javascript" src="sequence.js"></script>
<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
</head>
    <body>
        <div class="results"></div>
    </body>
</html>

<script type="text/javascript">
var id;
function getId() {
    id = "<?php echo $_GET['id']; ?>";
}

</script>
<script type="text/javascript" src="display.js"></script>
<script type="text/javascript" src="sequence.js"></script>
sequence.js

function getId() {
    id = "<?php echo $_GET['id']; ?>";
}
function seq()
{
    getId();
    updateHtml();   
}
seq();
请尝试以下操作: index.php

<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
</head>
    <body>
        <div class="results"></div>
    </body>
</html>

<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="display.js"></script>
<script type="text/javascript" src="sequence.js"></script>
<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
</head>
    <body>
        <div class="results"></div>
    </body>
</html>

<script type="text/javascript">
var id;
function getId() {
    id = "<?php echo $_GET['id']; ?>";
}

</script>
<script type="text/javascript" src="display.js"></script>
<script type="text/javascript" src="sequence.js"></script>

变量id;
函数getId(){
id=“”;
}
请尝试以下操作: index.php

<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
</head>
    <body>
        <div class="results"></div>
    </body>
</html>

<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="display.js"></script>
<script type="text/javascript" src="sequence.js"></script>
<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
</head>
    <body>
        <div class="results"></div>
    </body>
</html>

<script type="text/javascript">
var id;
function getId() {
    id = "<?php echo $_GET['id']; ?>";
}

</script>
<script type="text/javascript" src="display.js"></script>
<script type="text/javascript" src="sequence.js"></script>

变量id;
函数getId(){
id=“”;
}
函数getParameters(){
var url_params=window.location.search.substring(1);//删除字符:?
var params=url_params.split(“&”);
var res={};
for(变量i=0,c=params.length;i
返回一个对象{param:value}

函数getParameters(){
var url_params=window.location.search.substring(1);//删除字符:?
var params=url_params.split(“&”);
var res={};
for(变量i=0,c=params.length;i

在index.php中返回一个对象{param:value}

,在body中您可以这样做

<input type="hidden" name="hidden_id" id="hidden_id" value="<?=$_GET['id']?>">

在body内的index.php中,您可以这样做

<input type="hidden" name="hidden_id" id="hidden_id" value="<?=$_GET['id']?>">

config.js的URL没有id,因此id=“”它应该从初始链接回显id:
ttp://localhost:10600/js1/index.php?id=5
无法在.js文件中将php值分配给js。如果需要从URL获取id,则只能分配.php文件。请参见,不能在.js文件中将php值分配给js。实际上,使用URL重写之类的技巧是可能的。config.js的URL没有id,因此id=“”它应该回显初始链接中的id:
ttp://localhost:10600/js1/index.php?id=5
无法在.js文件中将php值分配给js。如果需要从URL获取id,则只能分配.php文件。请参见,不能在.js文件中将php值分配给js。实际上,这是可能的使用一些技巧,如URL重写。