Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传递变量形式javascript_Javascript_Variables - Fatal编程技术网

传递变量形式javascript

传递变量形式javascript,javascript,variables,Javascript,Variables,有一个隐藏字段希望在图形中使用此字段的值。 有可能吗?下面是我使用的代码示例 <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",

有一个隐藏字段希望在图形中使用此字段的值。 有可能吗?下面是我使用的代码示例

<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  }]

window.onload=函数(){
var teste=(document.getElementById(“valor”).value);
数据点:[
{标签:“苹果”,y:10},
{标签:“葡萄”,y:teste}]

谢谢

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

您的代码无法工作,因为您只需要关闭函数括号:

window.onload = function () {
  var teste = document.getElementById("valor").value;
  dataPoints: [
    { label: "apple",  y: 10  },
    { label: "grape",  y: teste  }
  ];
} // <= here
window.onload=函数(){
var teste=document.getElementById(“valor”).value;
数据点:[
{标签:“苹果”,y:10},
{标签:“葡萄”,y:teste}
];

}//
teste
是一个字符串。您必须将其解析为一个数字:
parseInt(teste,10)
您没有在函数中添加右大括号,那么什么不起作用?