jeudi 2 avril 2015

Run JavaScript inside Tags?

I've a JavaScript file that processes tab swithes. Here is the source:



$tCount = 0;

function SwitchToTab($id) {
if ($id < 0 || $id > $tCount) { $id = 0; }

for ($i = 0; $i < $tCount; $i++) { document.getElementById("tab" + $i).className = ""; }
document.getElementById("tab" + $id).className = "active";

for ($i = 0; $i < $tCount; $i++) { document.getElementById("area" + $i).style.display = "none"; }
document.getElementById("area" + $id).style.display = "";
}
function InitializeTabs($initialTabId, $tabsCount) {
$tCount = $tabsCount;
SwitchToTab($initialTabId);
}


I'm trying to make it as short as possible like this:



<script src="Resources/Tabs.js">InitializeTabs(0, 4);</script>


It doesn't works. I can run it if I do like this:



<script src="Resources/Tabs.js"></script>
<script>InitializeTabs(0, 4);</script>


So, is there any way to run JavaScript inside <script src="..."></script> tags? What I am missing?





Aucun commentaire:

Enregistrer un commentaire