我需要您的幫助。循環訪問數組值並生成不同的列名稱輸出
我想知道是否可以修改for循環,循環使用數組值並根據數組值輸出列名,但也只有(1)出現單個項生成不同的列名稱。下面是JavaScript代碼輸出到日期的畫面:
這裏是所需的輸出。正如你所看到的,它在視覺上更吸引眼球而不需要重複使用。因爲我將在列名後列出數字。
這裏是有問題的Javascript代碼:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
</style>
<script type="text/javascript">
function search_array(arr, str){
var searchExp = new RegExp(str,"gi");
return (searchExp.test(arr))?true:false;
}
function build_sheet() {
var Excel = new ActiveXObject("Excel.Application")
var Book = Excel.Workbooks.Add()
var Sheet = Book.ActiveSheet
var temp = "BNI to President","BNI to Director","BNI to Manager","BNA to President","BNA to Director","BNA to Manager"
var c = 2 /* Start position @ Column 2*/
for(var i = 0; i < temp.length; i++) {
if (search_array(temp[i], "BNI to") == true) {
Sheet.Cells(2,c).Value = "Briefing Notes (Info)"
}
if (search_array(temp[i], "BNA to") == true) {
Sheet.Cells(2,c).Value = "Briefing Notes (Approval)"
}
else {
Sheet.Cells(2,c).Value = temp[i]
}
++c
}
Excel.visible = true
Excel.quit()
Excel = null
}
</script>
</head>
<body>
</body>
</html>
'++ c' will be conditional i believe – charlietfl