2011-12-25 83 views
0

我正在使用c#.net和webbrowsercontrol。 我正在調用錨點標記的點擊事件。c#.net Webbrowser控件Anchor Tag Invoke Click事件不適用於交替行

應用有以下代碼:

HtmlElementCollection anchors = browser.Document.GetElementsByTagName("a"); 
foreach (HtmlElement anc in anchors) 
    { 
    if(anc.GetAttribute("href").ToLower().Contains("javascript:PFA".ToLower()) 
     { 
     anc.InvokeMember("click"); 
     } 
    } 

它適用於一行,不爲別的行。
來源網站有以下:

      <td colspan="1" id="tdborder" align="left" width="5%"> 
          <input name="appsWithStatusChg" type="checkbox" id="appsWithStatusChg1" alt='checkBoxLabel1' 
          label='checkBoxLabel1' 
          value="12114831" > 
          </td>      


          <td width="10%"> 

          <a class="PairLink" tabindex="17" href="javascript:postForApplicationData('12114831')"> 
          12/114,831 



          </td> 
          <td width="10%"> -</td> 
          <td width="14%"> US 2008-0209452 A1</td> 
          <td width="14%"> 1133-112US02</td> 
          <td width="11%"> 98449</td> 
          <td width="9%"> 12-24-2011</td> 
          <td width="17%"> 05-05-2008</td> 
          <td width="8%"> 




          <!--<input type="button" name="submitForIFW" value="Review" id="submitForIFW" onClick="postForIFWData('12114831')" tabindex="9" > 
          --> 
          <a href="javascript:postForIFWData('12114831')" tabindex="9"> View</a> 




          </td> 
         </tr> 

問題是,當我們試圖調用點擊事件 錨標記,其TR是wpsTableShdRow不工作。 其中tr爲wpsTableNrmRow的錨標記正在工作。

當我們嘗試手動訪問點擊事件時它工作。

+0

你能提供你的完整代碼和源文件嗎? – 2011-12-25 07:20:17

+0

我不會推薦使用GetElementsByTagName(...)。它在不同瀏覽器中的功能不同。 – CarneyCode 2011-12-25 07:32:52

+0

請提供完整的代碼。正如您在此處顯示的代碼是正確的。 – Zlatan 2011-12-25 17:17:19

回答

0
HtmlElementCollection anchors = browser.Document.GetElementsByTagName("a"); 
foreach (HtmlElement anc in anchors) 
    { 
    if(anc.GetAttribute("href").Contains("javascript:postForIFWData('12114831')")) 
     { 
     anc.InvokeMember("click"); 
     } 
    }