我有一个Webrowser,其中包含一些使用javascript更改的设置。我正在尝试使用示例here,但无法获得正确的语法
脚本看起来像这样
<div class="DisplayInput"><input type="radio" name="displaytype"
value="decimal" onclick="setdisplayType('decimal');" checked="checked"><a
href="javaScript:setdisplayType('decimal');"
onclick="s_objectID="javascript:setdisplayType('decimal');_1";return this.s_oc? this.s_oc(e):true">Decimal</a></div>
到目前为止,我已经尝试过这些但没有成功
this.webBrowser1.InvokeScript("setdisplayType");
this.webBrowser1.InvokeScript("setdisplayType('decimal')");
this.webBrowser1.InvokeScript("setdisplayType","decimal");
答案 0 :(得分:7)
不知道你的应用程序的错误发生了什么,也不知道setdisplayType
看起来是什么样的,我猜你可能正在尝试在加载之前调用函数setdisplayType
。根据MSDN文档......
之前不应该调用InvokeScript(String,Object()) 实现它的文档已完成加载。你可以检测何时 通过处理 LoadCompleted 事件,文档已完成加载。
也许你可以实现LoadCompleted
事件处理程序,然后调用你的脚本。
希望这有帮助!
答案 1 :(得分:1)
您必须传递一个Object数组作为第二个参数。 你可以这样做:
Object[] parameters = new Object[1]; //assuming your JS function has one parameter
parameters[0] = (Object)"yourStringParameter"; //for example the parameter is a string
yourBrowser.Document.InvokeScript("scriptName", parameters);
答案 2 :(得分:0)
试试这个:
sub DeleteNewSheets()
Dim ws, wsP As Worksheet
Dim ArrayOne As Variant
Application.DisplayAlerts = False
ArrayOne = Array("SheetA", "SheetB", "SheetC", "Sheet_n")
Set wsP = ThisWorkbook.Worksheets(ArrayOne) ' <--- ERROR #13
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> wsP.Name Then ws.Delete
Next ws
Application.DisplayAlerts = True
end sub