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
相關問題