首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用(IE )DOM修改网页以添加表单元素和JavaScript?

如何使用(IE )DOM修改网页以添加表单元素和JavaScript?
EN

Stack Overflow用户
提问于 2019-04-08 22:32:30
回答 1查看 41关注 0票数 0

我有第三方应用程序(编译),可以从HTML页面读取数据。这是通过创建一个Internet Explorer对象并加载一个空页面(.navigate "about:blank")完成的。表单元素通过Document.Body.innerHTML添加到页面。当通过Submit退出HTML页面时,应用程序通过CreateObject("WScript.Shell")读取提交数据。我想添加一些JavaScript来将输入数据组合到一个字符串中。也就是说,输入到输入文本框1和输入文本框2的数据与文本框3连接或/并根据复选框或单选按钮更改文本框3中的值。然后,我可以将这些值发送回应用程序。我怎样才能进一步修改这个空网页,使其包含java脚本来完成上述工作呢?

"g_objIE.Document.Body.innerHTML =“代码运行得很好。它非常基本,只包含表单元素。我可以简单地将java脚本添加到innerHTML中吗?我不这样认为。我尝试添加非常基本的代码,但收到一个“期望语句结束”错误。我试图插入:“

"& _“document.getElementById("demo").innerHTML =5+ 6;”&_

这是正常工作的代码。

代码语言:javascript
复制
' First step, set up the dialog (InternetExplorer)
Set g_objIE = CreateObject("InternetExplorer.Application")
g_objIE.Offline = True
g_objIE.navigate "about:blank"
g_objIE.document.focus()

' Wait for the navigation to the "blank" web page to complete
Do
    crt.Sleep 900
Loop While g_objIE.Busy

g_objIE.Document.body.Style.FontFamily = "Sans-Serif"

' Here's where we "create" the elements of our dialog box.  We basically
' throw HTML into the document, and IE loads it in real-time for us.
' 
' The hidden "ButtonHandler" input is used to tie IE and
' SecureCRT together such that SecureCRT can know when a
' button is pressed, etc.

g_objIE.Document.Body.innerHTML = _
  "<input type=radio name='LogMode' value='Append' AccessKey='A' checked>fpeth.3125 / Access" & _
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;" & _
        "<input type=radio name='LogMode' value='Overwrite' Accesskey='w' >fpeth.3070 / Core<br>" & _
    "<hr>" & _
    "<b>Path/File</b>&nbsp;&nbsp;<input name='fName' size='60' maxlength='60' tabindex=1><br>" & _
    "<b>HOST</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name='tID' size='30' maxlength='30'><br>" & _

    "<hr>" & _
    "<button name='Cancel' AccessKey='C' onclick=document.all('ButtonHandler').value='Cancel';><u>C</u>ancel</button>" & _
    "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>"

g_objIE.MenuBar = False
g_objIE.StatusBar = True
g_objIE.AddressBar = False
g_objIE.Toolbar = False
g_objIE.height = 270
g_objIE.width = 510   
g_objIE.document.Title = "TCP"
g_objIE.Visible = True
EN

回答 1

Stack Overflow用户

发布于 2019-04-11 08:05:46

  1. 您需要控制文档的HTML头和文档类型,这意味着您需要使用document.write而不是body.innerHTML。除了使脚本工作外,这还将使您能够控制HTML和doctypes。
  2. 要使操作更易于维护,请使用变量来保存您的HTML

代码语言:javascript
复制
Dim htmlString
htmlString = _
  "<!doctype html>" & _
  "<html>" & _
  "<head><title>tcp</title></head>" & _
  "<body>" & _
  "<input type=radio name='LogMode' value='Append' AccessKey='A' checked>fpeth.3125 / Access" & _
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;" & _
        "<input type=radio name='LogMode' value='Overwrite' Accesskey='w' >fpeth.3070 / Core<br>" & _
    "<hr>" & _
    "<b>Path/File</b>&nbsp;&nbsp;<input name='fName' size='60' maxlength='60' tabindex=1><br>" & _
    "<b>HOST</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name='tID' size='30' maxlength='30'><br>" & _
    "<hr>" & _
    "<button name='Cancel' AccessKey='C' onclick=document.all('ButtonHandler').value='Cancel';><u>C</u>ancel</button>" & _
    "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>" & _
    "<div id=demo>goes here</div>" & _
    "<script> " & _
    "   document.getElementById('demo').innerHTML = (5 + 6).toString(); " & _
    "</script>" & _
    "</body>" & _
    "</html>"

g_objIE.document.write(htmlString)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55575824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档