2015-08-15 91 views
1

我有这样的代码在w3school使用jQuery的javascript变量

<!DOCTYPE html> 
<html> 
<head> 

</head> 
<body> 

<script src="https://code.jquery.com/jquery-1.10.2.js"></script> 

<b>Books</b> 

<br> 

Author<br> 
<div id="author"></div> 
<br> 


<script> 
var getvar = "books.xml"; 

$("#author").load("books.xml author"); 


</script> 
</body> 
</html> 

这是工作......现在我需要用变量getvar

更换的books.xml测试此代码是不是.load工作

<script> 
var getvar = "books.xml"; 

$("#author").load("getvar author"); 


</script> 

任何帮助如何替换getvar变量?

回答

2

你需要从

$("#author").load("getvar author"); 

更新代码才能

$("#author").load(getvar + " author"); 

此外,移动你的脚本文件准备块内。

+0

我试过了,但没有奏效。 得到这个消息 - 504 - 网关超时 – syntaxcode

+0

以上应该已经奏效。您还应该将脚本移动到文档就绪区域内。 – nikhil

+1

知道了,现在它工作。由于NIKHIL – syntaxcode