2015-10-13 91 views
0

有一个隐藏字段想要使用该字段在图中的值。 有可能吗?以下是我使用的代码示例。传递变量形式javascript

<input type="hidden" name="valor" id="valor" value="20" /> 


window.onload = function() { 
var teste = (document.getElementById("valor").value); 
dataPoints: [ 
{ label: "apple", y: 10 }, 
{ label: "grape", y: teste }] 

谢谢

+0

'teste'是一个字符串。你将不得不把它解析为一个数字:'parseInt(teste,10)' – Andreas

+0

你还没有添加你的功能 – brk

+0

,所以什么不工作? – epascarello

回答

0

可以有效地获得价值按照你的建议。

您的代码不工作,因为你只需要关闭功能括号:

window.onload = function() { 
    var teste = document.getElementById("valor").value; 
    dataPoints: [ 
    { label: "apple", y: 10 }, 
    { label: "grape", y: teste } 
    ]; 
} // <= here