this resides inside the body tag in an HTML file and provides parameters to the jquery accordion开发者_如何学C function:
<script type="text/javascript">
$(function() {
$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
});
</script>
I want to save this as an external JavaScript file and call the function to do the same thing.
I am a newbie, please help!
replace it with: <script src="script.js"></script>
and create a new file called script.js with the code that used to be in the script tags:
$(function() {
$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
});
Erm, don't put <script>
tags into the <body>
. It's not a good practice.
Putting the JS code into an external file is much better for readability and functionality in general. Make a new file, let's say script.js
and paste in your code:
script.js
$(function() {
$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
});
And in your HTML file, instead of putting the JS code in between the <script>
tags, just add a src
attribute to tell the browser that the JS code is located in script.js
:
<script type="text/javascript" src="script.js"></script>
This should work:
<script type="text/javascript">
function makeTabs(elementId) {
jQuery("#" + elementId).tabs("#" + elementId + " div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
}
</script>
精彩评论