简体   繁体   English

Javascript InnerHTML文本未更改

[英]Javascript InnerHTML text not changing

For some reason the ID= employer won't change to employerCont (which is 34.07. It just continues to say test1 . Does anyone know why? 出于某种原因, ID= employer将不会更改为employerCont (这是34.07它只是不断地说test1 。有谁知道为什么吗?

<div id="main" style="background-color:#F0F0F0; width:500px; height:500px;">&nbsp;</div>
<div id="content" style="background-color:gray; width:500px; height:500px;">
<p id="employer">test1</p>
<p id="employee">test2</p>
</div>

<script src="C:\Documents and Settings\zx08067\Desktop\HSA_RaphaelGraph\raphael.js"></script>
<script src="C:\Documents and Settings\zx08067\Desktop\HSA_RaphaelGraph\g.raphael.js"></script>
<script language="javascript">

function calculatePercentages (var EE, var ER) {
    var sum = EE + ER;
    var EE_perc = EE / sum;
    var ER_perc = ER / sum;

}

//employee and employer contributions
var employeeCont = 251.34;
var employerCont = 34.07;

document.getElementById("employer").innerHTML = employerCont;

calculatePercentages(employeeCont, employerCont);

var tee=[0,0,500,500, 
{type:"path", path:"M58.5,50, C58.5,43 51.5,43 51.5,50, C51.5,57 58.5,57 58.5,50", fill:"green", "stroke-width":"0"},
{type:"path", path:"M52,52 L58,52 L58,70 L55,78 L52,70 L52,52", fill:"green", "stroke-width":"0"}, 
{type:"path", path:"M57,49, C57,46 53,46 53,49 C53,52.5 57,52.5 57,50", fill:"white", "stroke-width":"0"}
];

document.getElementById("main") = Raphael(tee);

</script>

Mistype. 类型错误。

function calculatePercentages (var EE, var ER)

Remove vars. 删除变量。

function calculatePercentages (EE, ER)

FIDDLE 小提琴

Similar to Cameron's answer, try calling once the document has finished loading. 与Cameron的答案类似,请在文档加载完成后尝试致电。

window.onload = function(){
    document.getElementById("employer").innerHTML = employerCont;
}

No jQuery required. 不需要jQuery。

Stripping away the non critical code to solve your specific question seemed to fix the issue. 剥离非关键代码以解决您的特定问题似乎可以解决此问题。 working code on JSBin JSBin上的工作代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM