我有返回数字数组的函数。接下来我必须在相关的结果 id 中显示相同数量的星星。作为 JavaScript 中的一个完整的菜鸟(仍在为验证而苦苦挣扎:P),我尝试了很多事情都无济于事。希望下面的代码片段(当前状态)能解决我的问题 -
function display(name1, number1, sign1, name2, number2, sign2, check, y_nat, o_nat) {
document.getElementById("yname").innerHTML = name1 ;
document.getElementById("ynumber").innerHTML = number1 ;
document.getElementById("ysign").innerHTML = sign1 ;
document.getElementById("oname").innerHTML = name2 ;
document.getElementById("onumber").innerHTML = number2 ;
document.getElementById("osign").innerHTML = sign2 ;
document.getElementById('result').innerHTML = check + '%';
/* I am trying to display y_nat[0] Stars in the result id - yr by calling a show_image(id, number) function! */
x = "yr";
document.getElementById("yr").innerHTML = show_image(x ,y_nat[0]) ;
x = "yl";
document.getElementById("yl").innerHTML = y_nat[1] ;
x = "yf";
document.getElementById("yf").innerHTML = y_nat[2] ;
x = "yp";
document.getElementById("yp").innerHTML = y_nat[3] ;
x = "ys";
document.getElementById("ys").innerHTML = y_nat[4] ;
x = "yi";
document.getElementById("yi").innerHTML = y_nat[5] ;
x = "or";
document.getElementById("or").innerHTML = o_nat[0] ;
x = "ol";
document.getElementById("ol").innerHTML = o_nat[1] ;
x = "of";
document.getElementById("of").innerHTML = o_nat[2] ;
x = "op";
document.getElementById("op").innerHTML = o_nat[3] ;
x = "os";
document.getElementById("os").innerHTML = o_nat[4] ;
x = "oi";
document.getElementById("oi").innerHTML = o_nat[5] ;
}
function show_image (id,number) {
var img = document.createElement("img");
img.src = "stars2.png";
x = number;
y = id;
for (i =0; i<x; i++){
document.getElementById(y).appendChild(img);
}
}//or something of this sort
如果问题不清楚,请告诉我。我仍在尝试解决它,并且非常有义务有人可以指导。我正在尝试学习 JavaScript。我正在尝试使用以下链接中的代码。 http://www.codingforums.com/archive/index.php/t-94715.html
提前致谢。