-1
這裏是我的腳本: page.js如何將腳本移動到頭標籤與JavaScript?
$(document).ready(function()
{
$.ajax
({
type: "GET",
url: "page/contenta.php",
dataType: "html",
cache: false,
success: function(response)
{
$("#main-content").html(response);
}
});
$("#contentb").live('click',function()
{
$.ajax
({
type: "GET",
url: "page/contentb.php",
dataType: "html",
cache: false,
success: function(response)
{
$("#main-content").html(response);
}
});
return false;
});
});
的index.php
<html>
<head>
javascript1.js (ex.)
javascript1.js (ex.)
javascript1.js (ex.)
</head>
<body>
<div id="main-content"></div>
<a href="#" id="contentb">CLICK</a>
</body>
</html>
contenta.php
<script type="text/javascript" src="js/javascripta.js"></script>
<div class="content"></div>
contentb.php
<script type="text/javascript" src="js/javascriptb.js"></script>
<div class="content"></div>
是否可以將腳本從contenta.php/contentb.php移動到index.php的標籤中? 例如結果:
<html>
<head>
javascript1.js (ex.)
javascript1.js (ex.)
javascript1.js (ex.)
<script type="text/javascript" src="js/javascripta.js"></script>
</head>
<body>
<div id="main-content">...Content A Loaded...</div>
<a href="#" id="contentb">CLICK</a>
</body>
</html>
和呼叫contentb.php後:
<html>
<head>
javascript1.js (ex.)
javascript1.js (ex.)
javascript1.js (ex.)
<script type="text/javascript" src="js/javascriptb.js"></script>
</head>
<body>
<div id="main-content">...Content B Loaded...</div>
<a href="#" id="contentb">CLICK</a>
</body>
</html>
如何將腳本放到頭標記使用javascript?
,它已經被執行。 –
是的,可以先移動腳本然後執行? – Schreiner
你應該解釋你爲什麼要這樣做。這可能是更好的方法。 –