} // doMove() doDelete()函数通过重新编号并压缩这两个数组实现问题的删除(将最后几行去掉): // 确认删除,然后在stemArray[]和ansArray[]中执行删除操作 function doDelete() { if (confirm("是否删除当前显示的问题?")) { if (stemArray.length > 0) { ID = stemArray[stemIx].substr(0,3); // 被删除问题的ID for (i=stemIx; i< stemArray.length-1; i++) stemArray[i] = stemArray[i].substr(0,3) + stemArray[i+1].substr(3); // 调整删除后的数组内容 stemArray.length--; } if (ansArray.length > 0) { delCount = 0; for (i=0; i< ansArray.length; i++) { if (ansArray[i].substr(0,3) == ID) { ansArray[i] = "ZZZ"; // 删除该项(排到最后面) delCount++; } else if (ansArray[i].substr(0,3) > ID) { tempID = " " + (parseInt(ansArray[i].substr(0,3)) - 1).toString(); tempID = tempID.substr(tempID.length-3, 3); ansArray[i] = tempID + ansArray[i].substr(3); } } ansArray.sort(); ansArray.length-=delCount; } doNav("< "); // 尝试退回前一问题 } } // doDelete() doNav()函数支持问题的导航,实现方法是改变需要显示问题的索引号,然后调用writeItem完成输出,代码略。 writeItem是这里最为复杂的函数。它按照问题类型的不同,将HTML代码以字符串的形式输出,这个字符串即为显示与编辑该问题的表单。表单为问题的每个可编辑部件提供了onChange()函数定义。当这个表单被写入页面中间的帧(ItemFrame),用户的编辑操作就会引起对saveStem()或saveAnswer()函数的调用,这些函数负责修改当前调查项目的stemArray[]或ansArray[]数组。 // 在浏览器中显示指定的问题 function writeItem(stemIx) { var IType = parseInt(stemArray[stemIx].substr(3,1)); // 问题类型 var NoOpinion = stemArray[stemIx].substr(4,1); // 是否允许不回答 var ID = stemArray[stemIx].substr(0,3); // 问题的ID for (ansIx=0; ansIx< ansArray.length; ansIx++) { if (ansArray[ansIx].substr(0,3) == ID) break; // 问题的回答 } if (ansIx >= ansArray.length) ansIx = -1; // 当前问题没有回答结果 outStr = '< HTML>< BODY BGCOLOR="#c0c0c0">' + '< FORM NAME="Item">' + '【当前问题编号】' + (stemIx + 1) + '【总问题数】 ' + stemArray.length + ' 【调查项目名字】 < %=PollName%>< /B>< BR>< /TABLE>< TEXTAREA NAME="Stem" ROWS=2 COLS=85 '+ 'onBlur="parent.ControlFrame.saveStem()">' + stemArray[stemIx].substr(5) + '< /TEXTAREA>< BR>'; if (NoOpinion == "Y" && IType != 5) outStr+=
(编辑:aniston)
|