传递变量形式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)
您没有在函数中添加右大括号,那么什么不起作用?