I have searched for an answer, but I haven't found a answer that address my issue, as I'm not how to word it as a search. My problem is that I want to use the same JS code for multiple HTML files, but only a few values need to be changed in the JS depending on the HTML file.
HTML
<!DOCTYPE html>
<!--Replace:: Line 14, Line 82: 'PROJECT' with name of the project; Line 15: '0' with the last counted image; line 94: 'PROJECT' with base name of picture files-->
<!--fill in any special instructions at each step in the text array.-->
<html>
<head>
<link type="text/css" rel="stylesheet" href="../defaultStyle.css"/>
<script type="text/javascript" src = "../buttons.js">
var num = 0
var NAME = PROJECT
var LAST = 100
var LAST1 = LAST-1
text[0] = "a"
text[1] = "b"
<!--...etc-->
</script>
<link type="text/css" rel="stylesheet" href="../projectStyle.css"/>
</head>
<body>
<div>
<p href="JavaScript:StepDisplay()" id="Step">PROJECT</p>
</div>
<div id="Text">
</div>
<div>
<button type="button" onClick="JavaScript:Back()"> Back</button>
<button type="button" onClick="JavaScript:Next()"> Next</button>
</div>
<div>
<img src="image/PROJECT (0).jpg" id="Pic">
</div>
</body>
</html>
***JavaScript***
var text = new Array[100]
var num = 0
var NAME = PROJECT
var LAST = 100
var LAST1 = 99
function Next(){
num = num + 1
if (num == LAST)
{num = 0}
stepnum = num.toString();
document.getElementById("Pic").src = "image/"+ NAME + "(" + stepnum + ").jpg"
document.getElementById("Text").innerHTML = text[num]
if (num == 0)
document.getElementById("Step").innerHTML = NAME
if (num == 1)
document.getElementById("Step").innerHTML = "Pieces"
if (num > 1)
document.getElementById("Step").innerHTML = "Step " + (num-1).toString();
}
function Back(){
num = num - 1
if (num < 0)
{num = LAST1}
stepnum = num.toString();
document.getElementById("Pic").src = "image/" + NAME + "(" + stepnum + ").jpg"
document.getElementById("Text").innerHTML = text[num]
if (num == 0)
document.getElementById("Step").innerHTML = NAME
if (num == 1)
document.getElementById("Step").innerHTML = "Pieces"
if (num > 1)
document.getElementById("Step").innerHTML = "Step " + (num-1).toString();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…