admin管理员组文章数量:1392007
I am trying to call another function in a different HTML file would I do something like this:
<script type = "text/javascript" src = "otherfile.html"></script>
This is the function getting called
function rankedScores(music, pattern) {
var scoresArray = urlScores(music, pattern);
function swap(a, b) {
var temp = scoresArray[a];
scoresArray[a] = scoresArray[b];
scoresArray[b] = temp;
}
for(var i = 0; i < scoresArray.length; i++) {
for(var x = 0; x < scoresArray.length - 1; x++) {
if (scoresArray[x].score > scoresArray[x + 1].score) {
swap(x, x + 1);
}
}
}
generateResults(scoresArray)
}
This is how im calling it:
rankedScores(albums, document.main.search.value);
I am trying to call another function in a different HTML file would I do something like this:
<script type = "text/javascript" src = "otherfile.html"></script>
This is the function getting called
function rankedScores(music, pattern) {
var scoresArray = urlScores(music, pattern);
function swap(a, b) {
var temp = scoresArray[a];
scoresArray[a] = scoresArray[b];
scoresArray[b] = temp;
}
for(var i = 0; i < scoresArray.length; i++) {
for(var x = 0; x < scoresArray.length - 1; x++) {
if (scoresArray[x].score > scoresArray[x + 1].score) {
swap(x, x + 1);
}
}
}
generateResults(scoresArray)
}
This is how im calling it:
rankedScores(albums, document.main.search.value);
Share
Improve this question
edited Dec 8, 2013 at 20:27
Pavlo
45k14 gold badges83 silver badges114 bronze badges
asked Dec 8, 2013 at 20:24
user2964960user2964960
291 silver badge9 bronze badges
2
- 3 Move it to a JS file. – SLaks Commented Dec 8, 2013 at 20:26
- If one of the pages is in an iframe, you can call its functions from the parent window. – Anderson Green Commented Feb 27, 2022 at 12:48
1 Answer
Reset to default 4You cannot do this. You should move it into a js
file and then include that js
file in your template:
<script type='text/javascript' src='some_other_file.js'></script>
本文标签: javascriptcall function in another HTML fileStack Overflow
版权声明:本文标题:javascript - call function in another HTML file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744763333a2623883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论