2014-02-06 27 views
0

我有一個N形式的網站。CsQuery:得到DomElement的後代

Foreach窗體我想選擇所有的輸入元素。 如何在代碼註釋中看到(1)+(2)?

doc = CQ.CreateFromFile("sample.html"); 
doc["form"].Each(e => 
     { 
      // 1) This returns only first level 
      IEnumerable<IDomElement> inputs = e.ChildElements; 

      // 2) This refers to all the document again 
      CQ currentForm = e.Cq().Select["input"] 
     } 

另一個問題:爲什麼DomElement.Cq()引用整個文檔而不是當前元素?我怎樣才能使它指向當前的元素?

感謝

回答

0

簡單的方法就是讓jQuery的方法做的工作適合你:

IEnumerable<IDomElement> inputs = e.Cq().Find("input"); 

Select方法總是選擇對整個DOM,它analagous只使用$(...)使用jQuery。 Find僅從jQuery中的上下文中選擇。