2013-10-24 33 views
0

的文本內部表單首先感謝您爲像我這樣的人提供的幫助。我的問題是以下幾點:使用WebBrowser.Document

我想在使用.NET的WebBrowser對象的網頁中編寫文本。問題是這個文本是在HTML結構中的一個表單中。該頁的代碼如下:

<form id="conv_weight" action="/es/" onsubmit="execute_weight(true); return false;"> 
<div> 

Quiero convertir: 
<div style="width: 152px"> 
<input type="text" name="amount" value="1" class="convert_from" onchange="execute_weight(true);" onkeyup="execute_weight(true);" style="width: 100%" /> 
</div> 

然後繼續其他項目。我想改變文字「金額」的價值。我怎麼能這樣做?

+1

哪個WebBrowser對象? Windows窗體版本,還是WPF版本,或其他? –

回答

0

如果您使用WebBrowser控件,請執行此操作。

HtmlElementCollection allInputTags = webBrowser1.Document.GetElementsByTagName("input"); 

      if (allInputTags!=null && allInputTags.Count > 0) 
      { 
       foreach (HtmlElement inp in allInputTags) 
       { 
        if (inp.Name == "amount") 
        { 
         inp.SetAttribute("value", "EnterYourValue"); 
         break; 
        } 
       } 
      } 
+0

它的工作!非常感謝你! – user2917354

+0

很高興我幫助:) – confusedMind