Ary*_*cha -1 html javascript css function
在以下功能中:
function EVOLVE1()
{
if(ATP>=evolveCost)
{
display('Your cell now has the ability to divide.');
display('Each new cell provides more ATP per respiration.');
ATP = ATP - evolveCost;
document.getElementById('cellscount').innerHTML = "Cells = " +cells;
document.getElementsById('ATPcount').innerHTML = "ATP + " +ATP;
document.getElementById('dividebtn').style.display = "inline";
document.getElementById('dividebtn').innerHTML = "Divide(" + divideCost + " ATP)";
}
else
{
display('Not enough ATP.');
}
}
Run Code Online (Sandbox Code Playgroud)
执行时,只执行前4个语句.最后3行没有任何效果(即,带有显示的按钮:none不可见,段落不会更改,按钮中的文本也不会更改).我不知道为什么会这样.另外,display()是一个简单的函数,可以在div中更改ap:
function display(x)
{
var z = document.getElementById('centretext').innerHTML;
document.getElementById('centretext').innerHTML = z + "<br>" + x;
}
Run Code Online (Sandbox Code Playgroud)
所以我不认为这会导致这个问题.HTML:
<div id="left" class = "format">
<button class="buttonformat" id = "respirebtn" onclick="respire()"> Respire </button>
<button class="buttonformat" id = "evolvebtn" onclick="EVOLVE1()"></button>
<button class="buttonformat" id = "dividebtn" onclick="divide()"></button>
<p id = "lefttext">
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#evolvebtn
{
display: none;
position: relative;
top:450px;
left:5px;
}
#dividebtn
{
display: none;
position: relative;
left:5px;
top:-30px;
}
Run Code Online (Sandbox Code Playgroud)
document.getElementsById不是一个功能.代码抛出异常(应该在您的控制台中可见)然后停止.
该函数没有s,因为它返回单个元素(因为ID在文档中必须是唯一的).
| 归档时间: |
|
| 查看次数: |
38 次 |
| 最近记录: |