2011-05-30 109 views
0

我沒有使用任何JavaScript插件,用JavaScript編輯並更新數組值?

<html> 
<head> 
<title>sample dynamic select list</title> 
<script language='javascript'> 
function changeContent(tablecell) 
{ 
    tablecell.innerHTML = "<INPUT type=text name=newname onBlur=\"javascript:submitNewName(this);\" value=\""+tablecell.innerHTML+"\">"; 
    tablecell.firstChild.focus(); 
} 
function submitNewName(textfield) 
{ 

    textfield.parentNode.innerHTML= textfield.value; 
} 
</script> 
</head> 
<?php 
$exrate = array("USD"=>array('sale'=>123,"buy"=>456)) 
?> 
<body> 
Double click on any cell. Then enter your own text and then tab out or click on other place. 
<table border=1 bgcolor=gray> 
<tr> 
<th>Currency</th> 
<th>Buy</th> 
<th>Sale</th> 
</tr> 
<tr> 
<td>USD</td> 
<td onDblClick="javascript:changeContent(this);"><?=$exrate["USD"]["sale"]?></td> 
<td onDblClick="javascript:changeContent(this);"><?=$exrate["USD"]["buy"]?></td> 
</tr> 
</table> 
</body> 
</html> 

當任一單元格,雙擊然後輸入自己的文字,然後從選項卡或點擊其他place.so我怎麼能在一個陣列更新這些數據例如商店,可以在每次編輯時存儲值?

+0

我不確定你在說什麼,但是你創建了一個數組,然後在每次編輯時推送這個值'array.push(newvalue)' – Ibu 2011-05-30 20:19:01

回答

1

你需要首先堅持這些值服務器端(如何存儲$ exrate?是否在會話,數據庫等?),然後你可以綁定一個甚至在tablecell的模糊事件,並使ajax請求更新您的服務器端存儲中的值。這就是說,有這麼多易於使用和輕量級的JavaScript框架/庫在那裏,我不明白爲什麼你會想這樣做手動(除了可能作爲一個學習練習或創新形式的自我flagelation) 。

+0

是的,我只是在學習,如果你說的太多東西我回到使用js框架... – newbie 2011-05-30 20:33:42