我想获取隐藏 HTML 字段中的变量值。我的代码如下:
<script lang=”text/javascript”>
Var counter;
Loop{
Some Code . . . .
Counter++;
}//end loop
</script>
<html>
<body>
// some code
<input type “hidden” name=”total” id=”total” value=”here I want to get Counter”>
</body>
</html>
最佳答案
1.) 获取元素的DOM对象
var elem = document.getElementById("total");
2.) 设置值
elem.value = your_variable;
示例:
var Counter = 0;
var elem = document.getElementById("total"),
while(condition == true) {
// some code
Counter++;
elem.value = Counter;
}
关于javascript - 获取 HTML 中的 javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8104236/