2015-10-13 140 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