[英]Store value in JavaScript array
我正在定義一個JavaScript數組,它將持有被單擊的復選框的行號和列號,如果選中了復選框,我將將行號和列號的值分配為1,否則我將放置0
我需要根據復選框的選中和取消選中進行一些操作,並將1,0存儲在DB中。
這就是我想要做的。
var sampleArray=new Array();
function setAll(column, value) {
var i, n = column.length;
for (i = 0; i <= n; ++i) {
column[i] = value;
}
}
if (//some condition){
if(cell is checked)
setAll(sampleArray,1); // here i am calling a function and setting the value in index to 1;
} else if (cell is unchecked)
{
setAll(sampleArray,0);
}
上面代碼的問題是它沒有存儲所有動作的值(選中和取消選中)。
有人可以幫我嗎? 是否可以在javascript中創建一種hashmap函數?
H<key, value>
其中鍵將是列號和行號,並且值將是0或1
function setAll(column, value) {
var i, n = column.length;
for (i = 0; i <= n; ++i) {
column[i] = value;
}
return (column)
}
if (//some condition){
if(cell is checked)
sampleArray= setAll(sampleArray,1); // here i am calling a function and setting the value in index to 1;
} else if (cell is unchecked)
{
sampleArray= setAll(sampleArray,0);
}
或者如果您想使用全局變量
function setAll(value) {
var i, n = sampleArray.length;
for (i = 0; i <= n; ++i) {
sampleArray[i] = value;
}
}
if (//some condition){
if(cell is checked)
setAll(1); // here i am calling a function and setting the value in index to 1;
} else if (cell is unchecked)
{
setAll(0);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.