2013-10-30 70 views
0

出於某種原因,ID= employer不會改變employerCont(這是34.07。它只是不斷地說test1。有誰知道爲什麼嗎?的Javascript innerHTML的文本不改變

<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> 
+2

你在控制檯中看到了什麼? – SLaks

+0

它顯示test1 –

+0

不。您在瀏覽器的Javascript控制檯中看到什麼?它會告訴你你的錯誤。 – SLaks

回答

1

與Cameron的答案類似,嘗試調用一次文檔完成加載。

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

不需要jQuery。

+0

好,我會接受你的答案,當它讓我。謝謝尼古拉斯:) –

+0

我做了很多工作,我不允許打電話到外部網站,因此我需要使用大量的原始JavaScript。人們害怕它,但它確實不是那麼糟糕。 –

+0

@NickChapman您也可以下載並將Jquery導入到您的HTML中。無需將其指向在線服務器。 – zurfyx

5

輸錯。

function calculatePercentages (var EE, var ER) 

刪除瓦爾。

function calculatePercentages (EE, ER) 

FIDDLE