我使用PHP,HTML & jQuery。比方说,这是我原来的工作“的index.html”如何将JavaScript和html拆分为多个文件
<script type="text/javascript" src="jquery.js"></script>
<script>
var p1 = "This is part 1";
var p2 = "This is part 2";
$(document).ready(function(){
alert(p1);
$('#content').html(p2);
});
</script>
<div id="content"></div>
<div id="content2">Hello</div>
我想打破代码为“index.html的” &“otherFile.notSureWhatExt”,但他们的工作,就好像在同一个文件。
的index.html:
<script type="text/javascript" src="jquery.js"></script>
<script type="notSureWhatType" src="otherFile.notSureWhatExt"></script>
<script>
var p1 = "This is part 1";
$(document).ready(function(){
alert(p1);
});
</script>
<div id="content"></div>
otherFile.notSureWhatExt:
<script>
var p2 = "This is part 2";
$(document).ready(function(){
$('#content').html(p2);
});
</script>
<div id="content2">Hello</div>
使用JSP,我可以简单地使用<%@包括文件= “otherFile.anyCustomExtAlsoWorks” %>。但我现在不在这里。我想要的是当调用index.html时,我可以看到消息框“这是第1部分”和底部是2“div2”,这是“这是第2部分”&“你好”。
谢谢你的提示。 – Coisox 2012-02-23 22:54:49