这个 javascript 代码运行良好
src='http://host/150.jpg'
// Function ActionItems Start
function ActionItems(){
var ActionItemsVar = document.getElementById("ActionItems").value;
switch (ActionItemsVar ){
case "150":
ActionItems1Var ="ActionItems1";
ActionItems2Var="ActionItems2";
ActionItems3Var="ActionItems3";
ActionItems4Var="ActionItems4";
document.getElementById("Image").innerHTML = "<img style='float:left' width='100%' height='100%'
src='http://host/150.jpg' alt='' title=''>";
break;
....
}
document.getElementById("ActionItems1").innerHTML = ActionItems1Var
document.getElementById("ActionItems2").innerHTML = ActionItems2Var
document.getElementById("ActionItems3").innerHTML = ActionItems3Var
document.getElementById("ActionItems4").innerHTML = ActionItems4Var
}
// Function ActionItems End
但是在 url 代码中使用变量将不起作用
src='http://host/'+ActionItemsVar+'.jpg'
// Function ActionItems Start
function ActionItems(){
var ActionItemsVar = document.getElementById("ActionItems").value;
switch (ActionItemsVar ){
case "150":
ActionItems1Var ="ActionItems1";
ActionItems2Var="ActionItems2";
ActionItems3Var="ActionItems3";
ActionItems4Var="ActionItems4";
document.getElementById("Image").innerHTML = "<img style='float:left' width='100%' height='100%'
src='http://host/'+ActionItemsVar+'.jpg'alt='' title=''>";
break;
...
}
document.getElementById("ActionItems1").innerHTML = ActionItems1Var
document.getElementById("ActionItems2").innerHTML = ActionItems2Var
document.getElementById("ActionItems3").innerHTML = ActionItems3Var
document.getElementById("ActionItems4").innerHTML = ActionItems4Var
}
// Function ActionItems End