Javascript 将JS变量声明为JS控制的HTML对象

Javascript 将JS变量声明为JS控制的HTML对象,javascript,jquery,javascript-events,Javascript,Jquery,Javascript Events,情况: 我有一个将输入数据转储到HTML块元素的函数,例如: function national(){ x=Number($('#nationalBudget').val()); a=x*2; $('#one').text(a);} 然后它将输入打印到id为“one”的任何元素中 问题: 我想用转储到HTML对象中的输出替换数组中的硬数字(例如100000和200000)。我尝试了以下方法: var TestVariable = <span id="one"></span&g

情况: 我有一个将输入数据转储到HTML块元素的函数,例如:

function national(){
x=Number($('#nationalBudget').val());
a=x*2;
$('#one').text(a);}
然后它将输入打印到id为“one”的任何元素中

问题: 我想用转储到HTML对象中的输出替换数组中的硬数字(例如100000和200000)。我尝试了以下方法:

var TestVariable = <span id="one"></span>;
coolnessGraph = new Array(
                       [TestVariable,'ROI w/ Local Spending'],
var TestVariable=;
coolnessGraph=新阵列(
[TestVariable,'ROI w/本地支出'],
我还尝试在第一次计算完成后,等待启动图形。
我的逻辑有错误吗?…语法?…如果有任何帮助,我们将不胜感激。

如果我阅读正确,您只需传递
$('#one')。text()
,或其变体,进入数组。我缺少什么吗?

嗯,它在fiddle中运行不正常,但您可以在这里查看我的代码结构。我尝试直接在数组中传递语句并通过var传递语句,但都不起作用。请注意,它在本地运行良好,因为某些原因,fiddle不接受我的代码。很好在本地,我指的是一切,但图形函数使用的是我的初始函数。@user1050809-你应该更加小心你的代码…我刚刚测试了你的小提琴,它有几个问题。你的标记不平衡,你没有导入图形jquery插件。例如,我复制了你的代码,并对它进行了一些处理,它基本上是工作的king.See here:。对于这样一个简单的任务,代码也非常复杂。请尝试重新编写代码,使其更易于维护(例如,在JS中生成所有文本,这样您就不会有那么多占位符html).同意,我更喜欢你在小提琴中设置问题的方式。是的,这对于我试图实现的目标来说相当复杂。我将通过尝试重新塑造,使其更易于维护。谢谢你的帮助!!!
  coolnessGraph = new Array(
                   [100000,'ROI w/ Local Spending'],
                   [200000,'ROI w/o Local Spending']
$("#ROIchart").jqBarGraph({
            data: coolnessGraph, // array of data for your graph
            title: false, // title of your graph, accept HTML
            barSpace: 10, // this is default space between bars in pixels
            width: 400, // default width of your graph
            height: 200, //default height of your graph
            color: '#F8981D', // if you don't send colors for your data this will be default bars color
            colors: false, // array of colors that will be used for your bars and legends
            lbl: '', // if there is no label in your array
            sort: false, // sort your data before displaying graph, you can sort as 'asc' or 'desc'
            position: 'bottom', // position of your bars, can be 'bottom' or 'top'. 'top' doesn't work for multi type
            prefix: '', // text that will be shown before every label
            postfix: '', // text that will be shown after every label
            animate: true, // if you don't need animated appearance change to false
            speed: 2, // speed of animation in seconds
            legendWidth: 100, // width of your legend box
            legend: false, // if you want legend change to true
            legends: false, // array for legend. for simple graph type legend will be extracted from labels if you don't set this
            type: false, // for multi array data default graph type is stacked, you can change to 'multi' for multi bar type
            showValues: true, // you can use this for multi and stacked type and it will show values of every bar part
            showValuesColor: '#fff' // color of font for values 
});
var TestVariable = <span id="one"></span>;
coolnessGraph = new Array(
                       [TestVariable,'ROI w/ Local Spending'],