1
我在单元格中有一个表格,显示用户用按钮输入的数字(使用onclick和showthis函数。我需要能够将该值存储为变量以便对其执行操作。我该怎么做?此
PS:我使用JavaScript和HTML如何在单元格中创建表格变量?
<script language="JavaScript" type="text/javascript">
function showthis(first){
document.getElementById("displaycell").innerHTML+=first;
}
</script>
<body>
<h1 align="center"> RPN Calculator </h1>
<table summary align="center" border="1" cellpadding="1" cellspacing="3">
<tr>
<th id="displaycell" colspan="5" type="text"> </td>
</tr>
<tr>
<td>
<button type="button" onclick="showthis('1')">1</button>
</td>
<td>
<button type="button" onclick="showthis('2')">2</button>
</td>
<td>
<button type="button" onclick="showthis('3')">3</button>
</td>
<!-- ... -->
你有任何的代码显示?如果我们不知道我们在做什么,我们就无能为力。 – zellio 2012-02-24 22:53:27
我认为HTML需要固定('
非常感谢! – user1231803 2012-02-25 17:09:47
回答
首先你不应该使用
+=
与innerHTML
这意味着你最终会与数字追加到细胞内部的价值,而不是覆盖它。会是一个更好的方式来处理。
接下来,在showthis中,您最好将值存储在变量中,以便将来可以直接从javascript访问它。
最后,再次访问该变量你可以读出来的
displaystore <td>
的或从变量读取它。来源
2012-02-24 22:54:19 zellio
RPN计算器
<表总结ALIGN = “中心” 的边界= “1” CELLPADDING = “1” CELLSPACING = “3”>把代码放在你的问题中,而不是作为注释。这种形式没用。 – zellio 2012-02-24 22:57:54
非常感谢! – user1231803 2012-02-25 17:08:31
这是你想要的吗? http://jsfiddle.net/CWQY2/
HTML:
JS:
来源
2012-02-24 23:06:35 ngen
非常感谢你! – user1231803 2012-02-25 17:09:38
相关问题