如何使用vbscript识别hta中checkbox的状态(checked Value)

How to identify the status (checked Value) of the checkbox in hta using vbscript

这是读取 excel 数据并将数据结果转换为 hta table 的代码, 并将编辑后的数据从 hta 写入 excel, 在我的 hta 页面 中,如果我 select 所需的复选框并单击 Click To Write 按钮,数据将存储在 excelsheet 通过 'yes' 或 'no' .

<!DOCTYPE html>
<head>
<HTA:application
Applicationname="MyApp"
BORDER="thin"
BORDERSTYLE="Normal"
Caption="yes"
ICON="D:\VBScriptTrainee\Ampeross-Qetto-Icon-developer.ico"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SINGLEINSTANCE="no"
NAVIGABLE="yes"
SYSMENU="yes"
VERSION="2.0"
WINDOWSTATE="maximize"/>

<title>Read Excel</title>
<link rel="stylesheet" href="D:\VBScriptTrainee\bootstrap-3.3.6-dist\css\bootstrap.min.css">

<style type="text/css">
body
{
background-color:#1abc9c;
}
P
{
font:bold 18px arial;
}
</style>
<script language="vbscript">

Public mySpan,selectexcel,objExcel,objWorkbook,rowCount,colCount,rowData,textData,sp,b,tempcol,checkData,i,j

On error resume next

Sub ReadExcelData()

  Set fileexcel =document.getelementbyid("file_id")
  file2=fileexcel.value
  'selectexcel      = inputbox("Enter the path","path here","D:\VBScriptTrainee\Sample.xlsx")
  Set objExcel      = CreateObject("Excel.Application")
  Set objWorkbook   = objExcel.Workbooks.open(file2)
  objExcel.visible  = True

  rowCount=objExcel.ActiveWorkbook.Sheets(1).UsedRange.Rows.Count
  colCount=objExcel.ActiveWorkbook.Sheets(1).UsedRange.Columns.Count

  Dim mySpan

  'colCount=colCount+1  
  tempcol=colCount
  'MsgBox(tempcol)
  'MsgBox(colCount)
  rowData="<table border=2>"  

  For intRow=1 to rowCount step 1

   'rowData=null
    rowData = rowData & "<tr>"
    For intCol=1 to colCount step 1


        'if ((intRow =1) and (intCol=tempcol)) then
             'objExcel.Cells(intRow,tempcol).Value = "Flag"
             'intRow =IntRow + 1 
        'End if
         If ((intRow <> 1) and (intCol = tempcol)) then
             'objExcel.Cells(1,tempcol).Value = "Flag"

                     rowData = rowData & "<td>" & "<input type='checkbox' id='flag_id' name='flag' />" & "</td>"
                     'checkData = cStr(rowData)


         End If





            If (intRow=1) Then

                rowData= rowData & "<td>" & "<b><font color=red>" & objExcel.Cells(intRow,intCol).Value & "</font></b>"  & "</td>"          
            Else    

                    rowData = rowData & "<td><div contentEditable='True'>"  & objExcel.Cells(intRow,intCol).Value  & "</div></td>"

            End If        
    Next
                    rowData = rowData & "</tr>"

  Next
                    rowData =rowData & "</table>"

             Set mySpan=document.getelementbyid("Span_id_two")
             mySpan.innerHTML = rowData & "<br>"

             'Set myExcel=document.getelementbyid("selectfile")
             'myExcel.innerHTML = selectexcel




             MsgBox "Data readed successfully",vbInformation


              document.getElementById("file_id").accept = ".xlsx"
End sub

Sub WriteExcelData()  

       mwresult = Msgbox ("Are you Sure to Write ?",vbOKCancel)

        If (mwresult=1) then

           Set mySpan=document.getelementbyid("Span_id_two")
           textData=mySpan.innerHTML

           Set tab=document.getElementsByTagName("table")(0)  

           mytable = document.getElementsByTagName("table")(0).rows.length      
Msgbox("myTable (rows Length) " & mytable)         
           mytable1= document.getElementsByTagName("table")(0).rows(0).cells.length  
Msgbox("myTable1 (rows Cells Length) " & mytable1)         

                For n = 0 to (mytable-1)  

                    For j = 0 To (mytable1-1)  

                        objExcel.Cells (n + 1, j + 1).Value = tab.Rows(n).Cells(j).innerHTML   
                        tableValue = tab.Rows(n).Cells(j).innerHTML 

                          If(tableValue="<INPUT id=flag_id type=checkbox CHECKED name=flag>") then

                                objExcel.Cells (n+1,mytable1).Value="Yes"

                          End If

                          If(tableValue="<INPUT id=flag_id type=checkbox name=flag>") then

                                objExcel.Cells (n+1,mytable1).Value="No"

                          End If                          

                    Next  

                Next   

                find ="<*>"
                rplace =" "

                objExcel.Cells.Replace find,rplace

                MsgBox "Data Exported Successfully",vbInformation                            

                objExcel.ActiveWorkbook.Save
                Set objExcel=nothing

        End If

                If(mwresult=2) then
                     MsgBox "You Selected Cancel",vbInformation
                End If

End sub

</script>

</head>

<body>


<center>

   <img src="D:\VBScriptTrainee\Excel.png" height=200 width=300/>

</center>


<center>
<h1 align="center" style="color:blue"><img src="D:\VBScriptTrainee\icon-developer-icon.png" height=100px width=100px/>
Read Excel**</h1><br>
<a style="a.link:red;a.hover:green;a.visited:blue;" href="D:\VBScriptTrainee\Hta_Rules.hta">Rules*</a><br><br>
<input class="btn btn-primary text-primary" type="file" id="file_id" name="file_id" accept=".xlsx">
<br>

<button class="btn btn-success" name="Read" value="Click To Read" onclick="ReadExcelData()">Click To Read</button>
<button class="btn btn-danger" name="Write" value="Click To Write" onclick="WriteExcelData()">Click To Write</button>



<br>
<br>
<p id="selectfile"></p>
<span ID="Span_id_two" Style="Color:blue;" name="text_name">
</span>
</div>
</div>
</div>
</center>
<marquee direction="Right" style="color:red;">***Note : Select only excel files***</marquee>

</body>
</html>

但是,我已经通过给出 html 格式来识别 selected 校验值数据,像这样

从上面的编码

If(tableValue="<INPUT id=flag_id type=checkbox CHECKED name=flag>") then

    objExcel.Cells (n+1,mytable1).Value="Yes"

End If

If(tableValue="<INPUT id=flag_id type=checkbox name=flag>") then

    objExcel.Cells (n+1,mytable1).Value="No"

End If

是否有任何替代方法来识别复选框的状态(是否选中复选框)。

这是我的excelsheet..

toCelcius 的函数定义语法错误

 function toCelsius(f) { //removed var
   return (5/9) * (f-32);
 }

您的浏览器随附的调试器工具(如控制台)可轻松找到这些问题。

当您在 JavaScript 中定义函数时,您不必像在强类型语言中那样包含某种 "type"。因此在 toCelsius 参数列表中添加 var 会导致错误。改成这样:

function toCelsius(f)