【发布时间】:2013-06-12 14:45:08
【问题描述】:
另一个菜鸟问题,根源在于对JS的理解很浅。
我正在构建一个小型的在线多步骤表单(通过隐藏 div 在单个 html 中制作),其中每次按下按钮都会增加一个具有固定数字的 var:
JS:
var score = 20;
function updateScore (){
score = score + 10;
result.value = score;
}
我希望显示分数:
使用 <input type="text" name="result" id="result" value="" size="" readonly> 我得到正确的值 (30)。
但是,当我使用 <script>document.write(result)</script> 时,我什么也得不到,而使用 <script>document.write(score)</script> 时,我得到原始 var (20)。
当我希望 var 在 jquery 进度条中输出时出现同样的问题。
如何确保它是更新的 var,显示在 document.write 中?
编辑:完成 JS
var currentLayer = 'lp';
var score = 10;
function showLayer(lyr){
hideLayer(currentLayer);
document.getElementById(lyr).style.visibility = 'visible';
document.getElementById(lyr).style.display = 'block';
currentLayer = lyr;
}
function hideLayer(lyr){
document.getElementById(lyr).style.visibility = 'hidden';
document.getElementById(lyr).style.display = 'none'
}
function goTo(lyr){
showLayer(lyr);
score = score + 10;
resultat.value = score;
}
function goToMinus(lyr){
showLayer(lyr);
score = score - 10;
resultat.value = score;
}
$(function() {
$( "#progressbar" ).progressbar({
value: score
});
});
【问题讨论】:
-
-
是否可以向我们展示更多代码和 HTML?我还不清楚你到底想做什么。
-
我已经添加了完整的js,如果有帮助的话...
-
@MarkWalters 感谢您的建议,但没有任何显示...
标签: javascript variables document.write input-field