gpt4 book ai didi

c# - GetElementsByTagName 在 WebBrowser 控件中不返回任何元素

转载 作者:行者123 更新时间:2023-12-02 20:25:30 26 4
gpt4 key购买 nike

这是我的代码:

    webBrowser1.ObjectForScripting = this;

string str =
"<html><head><script type=\"text/javascript\">" +
"var list = document.getElementsByTagName('abbr');" +
"len = list.length;" +
"for(i = 0;i < len;i++)" +
"{obj=list[i];obj.onclick=window.external.Test(this.id);}" +
"</script></head>" +
"<body>";

for (int i = 1000; i < 1100; i++)
{
str += "<abbr id=\'" + i.ToString() + "\'" +
">" + i.ToString() + " </abbr>";
}
str += "</body></html>";

webBrowser1.DocumentText = str;

谢谢

最佳答案

当您将脚本放入 <head> 时,它在 <body> 的内容之前执行已满载。有两种方法可以避免该问题: 您可以将脚本放在结尾 </body> 之前。 -标记或执行脚本 onload .

window.onload = function () {
// Insert code that depends on a loaded body here.
}

关于c# - GetElementsByTagName 在 WebBrowser 控件中不返回任何元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4912740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com