当前位置: 代码迷 >> C# >> c# webbrowser 给内容的元素事件解决方案
  详细解决方案

c# webbrowser 给内容的元素事件解决方案

热度:64   发布时间:2016-05-05 04:34:35.0
c# webbrowser 给内容的元素事件
   
webbrowser 名子是web

里的内容

<script language="javascript" type="text/javascript">function ok(str){      
document.getElementById('sanswer').value=str;}
</script><body><br><input type='text' value='89' id='sanswer' name='sanswer'><br>

<input type='radio' name='answer' id='answer' onclick='ok(0)' value='0'>Please wake me up at 5 o'clock.<br>
<input type='radio' name='answer' id='answer' onclick='ok(1)' value='1'>He wakes up at six o'clock in the morning every day, too.<br>



                    //MessageBox.Show("");
                    web.Document.GetElementById("sanswer").AttachEventHandler("onclick", new EventHandler(button6_Click));  

         
给sanswer加了事件,但是第二次,重新给webbrowser值


<script language="javascript" type="text/javascript">function ok(str){      
document.getElementById('sanswer').value=str;}
</script><body><br><input type='text' value='89' id='sanswer' name='sanswer'><br>

<input type='radio' name='answer' id='answer' onclick='ok(0)' value='0'>1111<br>
<input type='radio' name='answer' id='answer' onclick='ok(1)' value='1'>2222.<br>



                    //MessageBox.Show("");
                    web.Document.GetElementById("sanswer").AttachEventHandler("onclick", new EventHandler(button6_Click));  


后值后onclick事件就不起作用了
但是在前面加了一个MessageBox.Show("");,就好了,
求教~~~~~~~~~~~~~
------解决思路----------------------
在webbrowser钟加一个timer1  时间1S  在原来messagebox.show位置写上timer1.start();
  private void timer1_Tick(object sender, EventArgs e)
        {
timer1.stop();
            web.Document.GetElementById("sanswer").AttachEventHandler("onclick", new EventHandler(button6_Click));
}
  相关解决方案