当前位置: 代码迷 >> vbScript >> 为什么这段脚本失效?该如何解决
  详细解决方案

为什么这段脚本失效?该如何解决

热度:3838   发布时间:2013-02-26 00:00:00.0
为什么这段脚本失效?
下述代码中 "document.formfoo.txtHardDiskSN.value   =   hex(f.serialnumber)
"没有成功的执行,该文本框没有成功显示硬盘序列号,但 "document.write(hex(f.serialnumber)) "却能够成功打印这个硬盘序列号。何解?

<html>  
  <head>
    <script   language= "vbscript ">        
    set       fs       =       CreateObject( "scripting.filesystemobject ")  
    set       f   =   fs.GetDrive( "c: ")  
    document.write(hex(f.serialnumber))
    document.formfoo.txtHardDiskSN.value   =   hex(f.serialnumber)
    </script>
    </head>  
    <body>
    <form   name= "formfoo "> <input   value= "aaa "   name= "txtHardDiskSN "   type= "text "> </input>   </FORM> </BODY>
    </html>

------解决方案--------------------------------------------------------
因为你的脚本写在了控件之前,脚本执行的时候控件还没加载。你把脚本写到控件后就可以了:
<html>
<head>
</head>
<body>
<form name= "formfoo "> <input value= "aaa " name= "txtHardDiskSN " type= "text "> </input> </FORM> </BODY>
<script language= "vbscript ">
set fs = CreateObject( "scripting.filesystemobject ")
set f = fs.GetDrive( "c: ")
document.write(hex(f.serialnumber))
document.all.formfoo.txtHardDiskSN.value = hex(f.serialnumber)
</script>
</html>
  相关解决方案