你这个方法不大标准,应该这样比较简单。(我只会VBScript,但其中的方法都是通用的。)<script language="VBScript" type="text/VBScript"> '生成submit,看似比Write方法复杂,但是对于程序来说更加灵活。 Set tInputSubmit=document.createElement("INPUT") 'Set 相当于JavaScript里的var With tInputSubmit .value="submit" .type="submit" End With '插入submit document.insertAdjacentElement "BeforeEnd",tInputSubmit Set tP=document.createElement("P") With tP .innerText=tInputSubmit.outerHTML '元素的outerHTML返回元素的全部HTML End With document.insertAdjacentElement "BeforeEnd",tP
另外有一个更加详细的演示给你,是我为了申请VBScript版而在水园搞宣传活动制作的VBS演示。其中用到了FORM和INPUT。将下面的代码拷贝到记事本里,取名为Logon.vbs,双击vbs文件可以直接运行。将弹出CSDN的登陆界面,我就是用它进入CSDN的。其中的一些方法不是VBScript特有的,可以移植到JavaScript里。(我学习DOM的教材里就是JavaScript的演示程序。)Dim pubLogonURLpubLogonURL="http://expert.csdn.net/member/logon.asp"Dim pubWindow Dim pubDocumentDim pubTimeoutpubTimeout=15Set pubWindow=CreateObject("InternetExplorer.Application") pubWindow.Visible = True pubWindow.Navigate "about:blank"Set pubDocument=DocumentGetByWindows(pubWindow,pubTimeout) Set tObj=LogonGetByCreate(pubDocument) pubDocument.body.innerHTML=tObj.outerHTML '特别注意上一句,把它改成pubDocument.body.innerText=tObj.outerHTML看看有什么区别?Function DocumentGetByWindows(pWindow,pTimerout) tOnLoopTimer=Timer Do tTimeout=Abs(tOnLoopTimer-Timer) Loop Until pWindow.ReadyState=4 Or tTimeout>pTimerout Set DocumentGetByWindows=pWindow.document End FunctionFunction LogonGetByCreate(pDocument) With pDocument.body .style.backgroundcolor="rgb(0,0,0)" .style.color="rgb(255,255,255)" .style.fontfamily="宋体" .style.fontsize="9pt" End With
Set tForm=pDocument.createElement("<FORM name='alogon'>") With tForm .method="POST" .target="_blank" .name="alogon" .action=pubLogonURL End With Set tP=pDocument.createElement("P") tP.innerText="请输入ID:" tForm.insertAdjacentElement "BeforeEnd",tP Set tInputName=pDocument.createElement("<INPUT NAME='name'>") With tInputName .type="text" .name="name" .size="7" .height=22 .style.backgroundcolor="rgb(192,255,0)" .style.color="rgb(0,0,0)" .style.fontfamily="宋体" .style.fontsize="9pt" .style.borderleft="1px solid rgb(128,128,128)" .style.borderright="1px solid rgb(255,255,255)" .style.bordertop="1px solid rgb(128,128,128)" .style.borderbottom="1px solid rgb(255,255,255)" End With tForm.insertAdjacentElement "BeforeEnd",tInputName Set tP=pDocument.createElement("P") tP.innerText="请输入密码:" tForm.insertAdjacentElement "BeforeEnd",tP Set tInputPass=pDocument.createElement("<INPUT NAME='pass'>") With tInputPass .type="password" .name="pass" .size="7" .height=22 .style.backgroundcolor="rgb(192,255,0)" .style.color="rgb(0,0,0)" .style.fontfamily="宋体" .style.fontsize="9pt" .style.borderleft="1px solid rgb(128,128,128)" .style.borderright="1px solid rgb(255,255,255)" .style.bordertop="1px solid rgb(128,128,128)" .style.borderbottom="1px solid rgb(255,255,255)" End With tForm.insertAdjacentElement "BeforeEnd",tInputPass Set tInputType=pDocument.createElement("<INPUT NAME='type'>") With tInputType .type="text" .name="type" .size="7" .height=22 .value=1 .style.backgroundcolor="rgb(192,255,0)" .style.color="rgb(0,0,0)" .style.fontfamily="宋体" .style.fontsize="9pt" .style.borderleft="1px solid rgb(128,128,128)" .style.borderright="1px solid rgb(255,255,255)" .style.bordertop="1px solid rgb(128,128,128)" .style.borderbottom="1px solid rgb(255,255,255)" .style.visibility="hidden" End With tForm.insertAdjacentElement "BeforeEnd",tInputType Set tP=pDocument.createElement("P") tP.innerText="" tForm.insertAdjacentElement "BeforeEnd",tP Set tButtom=pDocument.createElement("INPUT") With tButtom .type="submit" .value="进入" .height=20 .style.backgroundcolor="rgb(100,150,200)" .style.color="rgb(255,255,255)" .style.fontfamily="宋体" .style.fontsize="9pt" .style.borderleft="2px solid rgb(255,255,255)" .style.borderright="2px solid rgb(0,50,100)" .style.bordertop="2px solid rgb(255,255,255)" .style.borderbottom="2px solid rgb(0,50,100)" End With tForm.insertAdjacentElement "BeforeEnd",tButtom Set LogonGetByCreate=tForm End Function
因为我有一段javascript程序,它生成了一段挺复杂的、挺长的html代码,我想取到这段html代码。用alert方法能把它显示出来,但无法拷贝啊,请问有什么办法能把它显示在网页上,以方便拷贝。
<div id=mydiv><input type=checkbox><input type=button></div>
<script>
document.write("<textarea rows=5>"+document.all.mydiv.innerHTML+"</textarea>");
</script>
'生成submit,看似比Write方法复杂,但是对于程序来说更加灵活。
Set tInputSubmit=document.createElement("INPUT")
'Set 相当于JavaScript里的var
With tInputSubmit
.value="submit"
.type="submit"
End With
'插入submit
document.insertAdjacentElement "BeforeEnd",tInputSubmit Set tP=document.createElement("P")
With tP
.innerText=tInputSubmit.outerHTML
'元素的outerHTML返回元素的全部HTML
End With
document.insertAdjacentElement "BeforeEnd",tP
</script>虽然上述程序是VBscript,但是其中的DHTML方法和属性可以用在JavaScript里。
Dim pubDocumentDim pubTimeoutpubTimeout=15Set pubWindow=CreateObject("InternetExplorer.Application")
pubWindow.Visible = True
pubWindow.Navigate "about:blank"Set pubDocument=DocumentGetByWindows(pubWindow,pubTimeout)
Set tObj=LogonGetByCreate(pubDocument)
pubDocument.body.innerHTML=tObj.outerHTML
'特别注意上一句,把它改成pubDocument.body.innerText=tObj.outerHTML看看有什么区别?Function DocumentGetByWindows(pWindow,pTimerout)
tOnLoopTimer=Timer
Do
tTimeout=Abs(tOnLoopTimer-Timer)
Loop Until pWindow.ReadyState=4 Or tTimeout>pTimerout Set DocumentGetByWindows=pWindow.document
End FunctionFunction LogonGetByCreate(pDocument) With pDocument.body
.style.backgroundcolor="rgb(0,0,0)"
.style.color="rgb(255,255,255)"
.style.fontfamily="宋体"
.style.fontsize="9pt"
End With
Set tForm=pDocument.createElement("<FORM name='alogon'>")
With tForm
.method="POST"
.target="_blank"
.name="alogon"
.action=pubLogonURL
End With Set tP=pDocument.createElement("P")
tP.innerText="请输入ID:"
tForm.insertAdjacentElement "BeforeEnd",tP Set tInputName=pDocument.createElement("<INPUT NAME='name'>")
With tInputName
.type="text"
.name="name"
.size="7"
.height=22
.style.backgroundcolor="rgb(192,255,0)"
.style.color="rgb(0,0,0)"
.style.fontfamily="宋体"
.style.fontsize="9pt"
.style.borderleft="1px solid rgb(128,128,128)"
.style.borderright="1px solid rgb(255,255,255)"
.style.bordertop="1px solid rgb(128,128,128)"
.style.borderbottom="1px solid rgb(255,255,255)"
End With
tForm.insertAdjacentElement "BeforeEnd",tInputName Set tP=pDocument.createElement("P")
tP.innerText="请输入密码:"
tForm.insertAdjacentElement "BeforeEnd",tP Set tInputPass=pDocument.createElement("<INPUT NAME='pass'>")
With tInputPass
.type="password"
.name="pass"
.size="7"
.height=22
.style.backgroundcolor="rgb(192,255,0)"
.style.color="rgb(0,0,0)"
.style.fontfamily="宋体"
.style.fontsize="9pt"
.style.borderleft="1px solid rgb(128,128,128)"
.style.borderright="1px solid rgb(255,255,255)"
.style.bordertop="1px solid rgb(128,128,128)"
.style.borderbottom="1px solid rgb(255,255,255)"
End With
tForm.insertAdjacentElement "BeforeEnd",tInputPass Set tInputType=pDocument.createElement("<INPUT NAME='type'>")
With tInputType
.type="text"
.name="type"
.size="7"
.height=22
.value=1
.style.backgroundcolor="rgb(192,255,0)"
.style.color="rgb(0,0,0)"
.style.fontfamily="宋体"
.style.fontsize="9pt"
.style.borderleft="1px solid rgb(128,128,128)"
.style.borderright="1px solid rgb(255,255,255)"
.style.bordertop="1px solid rgb(128,128,128)"
.style.borderbottom="1px solid rgb(255,255,255)"
.style.visibility="hidden"
End With
tForm.insertAdjacentElement "BeforeEnd",tInputType Set tP=pDocument.createElement("P")
tP.innerText=""
tForm.insertAdjacentElement "BeforeEnd",tP Set tButtom=pDocument.createElement("INPUT")
With tButtom
.type="submit"
.value="进入"
.height=20
.style.backgroundcolor="rgb(100,150,200)"
.style.color="rgb(255,255,255)"
.style.fontfamily="宋体"
.style.fontsize="9pt"
.style.borderleft="2px solid rgb(255,255,255)"
.style.borderright="2px solid rgb(0,50,100)"
.style.bordertop="2px solid rgb(255,255,255)"
.style.borderbottom="2px solid rgb(0,50,100)"
End With
tForm.insertAdjacentElement "BeforeEnd",tButtom Set LogonGetByCreate=tForm
End Function
对话框出来时,用
ctrl+c就可了
在2000,XP下都可以的。
再粘贴就是了=======================
◢◣。 ◢◣。
◢★◣。 ◢★◣。
◢■■◣。 ◢■■◣。
◢■■■◣。 ◢■■■◣。
︸︸||︸︸ !!︸︸||︸︸
愿您有快乐的每一天 ^_^!!