如何解决Webbrowser-从第一个下拉列表中选择一个项目后,更新第二个下拉列表
|| 我的目标是从第二个下拉列表中选择一个项目后更新第二个下拉列表。任何帮助,将不胜感激。 我无法检测到何时在Webbrowser控件中启动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;
}
解决方法
您可以使用jquery来做到这一点。
$(function() {
$(\"#cboCity\").change(function() {
var currentSelection = $(this).val();
//grab the other items
//loop trough them
//inert into $(\"cboDistrict\").html();
});
});
, 为什么不使用jQuery以及即使在下拉菜单中也进行更改?
http://api.jquery.com/change/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。