Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/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 - Fatal编程技术网

Javascript 需要将变量放入对象中

Javascript 需要将变量放入对象中,javascript,Javascript,如何将变量放入json 参见示例 $('.thermometer-noconfig').thermometer({ percent: 10, speed: 'slow' }) /* thermometers with config */ $('.thermometer-config').thermometer({ percent: 10, speed: 'slow' }) 我需要的不是数字“10”,而是变量测试 我该怎么做,请帮帮我 your_var

如何将变量放入json 参见示例

$('.thermometer-noconfig').thermometer({

    percent: 10,   
    speed: 'slow'
})
/* thermometers with config */
$('.thermometer-config').thermometer({

    percent: 10, 
    speed: 'slow'
})
我需要的不是数字“10”,而是变量测试 我该怎么做,请帮帮我

your_var = 'whatever'; 
$('.thermometer-noconfig').thermometer({

    percent: 10,   
      speed: 'slow'
    })
    /* thermometers with config */
    $('.thermometer-config').thermometer({

      percent: your_var , 
      speed: 'slow'
    })
现在我不知道“温度计”是什么/或者它需要什么-但是你可以通过以下任一项:

$('.thermometer-config').thermometer(myThing);
或者,如果需要JSON格式:

$('.thermometer-config').thermometer(myJsonThing);

myThing
上的
JSON.stringyfy()的输出是

{“百分比”:“测试”,“速度”:“慢速”}


,但由于您没有通过http将此数据传递给服务,我不知道您为什么要求json格式,如果需要,请告诉我们更多。

您是否尝试将
10
替换为
test
?此外,这不是json,这些是javascript对象文本。*我看到您现在已经删除了问题中对json的引用:PHi我需要将我的一些计算显示为温度计,但当我将计算插入函数时,它会停止工作这里是$(“#start2”)。单击(function(){G=$(“#test”).val()7.15;Pi=3.1415926;S=0.25;S=0.25;pid;pid;S=0.25;piddd;V;U=0.25;p=10;D=10;D=10;D=10;D=10;D=10;D=10;D=0;D=0;D=0;D=0.10;D=10;D=10;D=10;D=10;D=10;H=0.25;p=10;p=10;p=10;p=10;p=10;D=10;D=10;p=10;D=10;D=10;p=10;p=10;D=10;p=0.25;p=10;p=0.25;p=10;p=10;p=10;p=10;p=10;p=10;p=10;p=0.25;p=0.25;p=0.25;pid;p;p=‘温度计无配置’。温度计({percent:T2,speed:'slow'})/带配置的温度计*/$('.therometer config')。温度计({percent:h2,speed:'slow'})});Hi@user3127698,可能最好问一个新问题
$('.thermometer-config').thermometer(myJsonThing);