Webbrowser - 从第一个下拉列表中选择项目后更新第二个下拉列表
我的目标是更新第二个下拉列表,该列表在从第一个下拉列表中选择项目后更新。任何帮助将不胜感激。 我无法检测到 web 浏览器控件中何时启动 ajax 活动。我已尝试此线程中的指令但没有成功,实现了以下类: HTML:
<html>
<Head>
<script type="text/javascript" src="http://myweb.com/scripts/jquery_1.5.js">
</head>
<body>
<select id =”cboCity”>
<option value=”1”> C1 </option>
<option value=”2”> C2 </option>
<option value=”3”> C3 </option>
<select id =”cboDistrict”>
<option value=”1”> D1 </option>
<option value=”2”> D2 </option>
<option value=”3”> D3 </option>
</body>
</html>
C# 代码:
System.Windows.Forms.Timer timer1;
HtmlElement city = webbrowser1.doc.GetElementById("cboCity ");
city.Focus();
city.SetAttribute("value", "2");
city.InvokeMember("onchange");
timer1 = new System.Windows.Forms.Timer();
timer1.Tick +=new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Start();
private void timer1_Tick(object sender, EventArgs e)
{
HtmlElement district = webbrowser1.doc.GetElementById("cboDistrict");
district.Focus();
district.SetAttribute("value", "3");
district.InvokeMember("onchange");
timer1.Stop();
this.timer1.Enabled = false;
}
My goal is to update second dropdown list which is updated after choosing an item from the first dropdown list. Any help would be appreciated.
I can't detect when start ajax activity in webbrowser control. I've tried instructions in this thread with no success, implemented the following class:
HTML:
<html>
<Head>
<script type="text/javascript" src="http://myweb.com/scripts/jquery_1.5.js">
</head>
<body>
<select id =”cboCity”>
<option value=”1”> C1 </option>
<option value=”2”> C2 </option>
<option value=”3”> C3 </option>
<select id =”cboDistrict”>
<option value=”1”> D1 </option>
<option value=”2”> D2 </option>
<option value=”3”> D3 </option>
</body>
</html>
C# Code:
System.Windows.Forms.Timer timer1;
HtmlElement city = webbrowser1.doc.GetElementById("cboCity ");
city.Focus();
city.SetAttribute("value", "2");
city.InvokeMember("onchange");
timer1 = new System.Windows.Forms.Timer();
timer1.Tick +=new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Start();
private void timer1_Tick(object sender, EventArgs e)
{
HtmlElement district = webbrowser1.doc.GetElementById("cboDistrict");
district.Focus();
district.SetAttribute("value", "3");
district.InvokeMember("onchange");
timer1.Stop();
this.timer1.Enabled = false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 jquery 来做到这一点。
You can use jquery to do that.
为什么不使用 jQuery 并在下拉菜单中进行更改?
http://api.jquery.com/change/
Why not use jQuery and the change even on the dropdown?
http://api.jquery.com/change/