Webbrowser - 从第一个下拉列表中选择项目后更新第二个下拉列表

发布于 2024-11-16 10:36:37 字数 1352 浏览 4 评论 0原文

我的目标是更新第二个下拉列表,该列表在从第一个下拉列表中选择项目后更新。任何帮助将不胜感激。 我无法检测到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那片花海 2024-11-23 10:36:37

您可以使用 jquery 来做到这一点。

$(function() {
    $("#cboCity").change(function() {
        var currentSelection = $(this).val();
//grab the other items
//loop trough them
//inert into $("cboDistrict").html();
    });
});

You can use jquery to do that.

$(function() {
    $("#cboCity").change(function() {
        var currentSelection = $(this).val();
//grab the other items
//loop trough them
//inert into $("cboDistrict").html();
    });
});
私野 2024-11-23 10:36:37

为什么不使用 jQuery 并在下拉菜单中进行更改?
http://api.jquery.com/change/

Why not use jQuery and the change even on the dropdown?
http://api.jquery.com/change/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文