今天用C#写一个登陆论坛发帖的程序,用webBrowser时出现了个小问题,请教下!页面的下拉框源码如下 <select id="cltype" onchange="szchange();"><option selected>请选择您的职业</option><option value="0">学生</option><option value="1">老师</option>另外一个下拉框是根据这里选择的职业动态生成的;默认的<select id="clall" onchange="allchange();"><option selected>请选择您的月薪</option> 是这样,选择了上面的以后,网页加入了<option value="1000">1000</option><option value="10000">10000</option>这样的,我用webBrowser SetAttribute 不起任何作用, 在页面CreateElement("script") 使用脚本来选择也无效,我确定我的代码没有问题!直接 document.getElementById('clall').add(new Option("1000","1000") 也无效,请教这里应该怎么处理才能设置这里的clall控件的选中值!
解决方案 »
- 怎么复制和删除xml
- battion 奇怪的事件问题
- C#中新建线程时,线程能否启动一个带参数的函数
- c# 中如何修改一个图片的图像质量
- 听说微软有VB.NET转换到C#的软件,但不知道这个软件名(或插件)。若是在线转换的话,网址是什么?
- 怎么用用InstallUtil.exe安装windows service?
- 多线程查询Access为什么会卡程序界面,就好象程序死了一样
- System.Timers.Timer的Interval最长设置多长时间间隔啊 (三个月一执行可以吗)
- datagrid
- 我装VS.NET正式版之前忘记装IIS,出现问题了,如何解决?
- FORM.SHOW();和FORM_LOAD()问题
- win2000sp4安装MDAC2.8,总是提示odbcconf.exe没有通过微软数字签名
<script type="text/javascript">
var clall=document.getElementById("clall");
var option=document.createElement("option");
option.text = "1000元";
option.id="option_1000";
option.value="1000";
clall.appendChild(option);
//-------------
option=document.createElement("option");
option.text = "10010元";
option.id="option_10010";
option.value="10010";
clall.appendChild(option);
</script>
/// 选中select标签
/// </summary>
/// <param name="webbrowser"></param>
/// <param name="controlName"></param>
/// <param name="selectString"></param>
public void GetSelect(System.Windows.Forms.WebBrowser webbrowser, string controlName, string selectString)
{
System.Windows.Forms.HtmlElementCollection collection = webbrowser.Document.All[controlName].Children;
for (int i = 0; i < collection.Count; i++)
{
if (collection[i].GetAttribute("innerText") == selectString)
{
webbrowser.Document.All[controlName].Children[i].SetAttribute("selected", "selected");
return;
}
}
}controlName是控件的id
selectString是需要选中的那一列的值
<script type="text/javascript">
var clall=document.getElementById("clall");
var option=document.createElement("option");
option.text = "1000元";
option.id="option_1000";
option.value="1000";
clall.appendChild(option);
//-------------
option=document.createElement("option");
option.text = "10010元";
option.id="option_10010";
option.value="10010";
clall.appendChild(option);
document.getElementById("option_10010").selected=true;//选中 option有id的情况下
clall.selectedIndex=0;//选中 从0开始 在option没有id的情况下
</script>
hElement = WebBrowser.Document.GetElementById("selectId");
hElement.SetAttribute("selectedIndex", "1");