문제

I've a website with N forms.

Foreach form I want to choose all the input elements. How can I do that see (1) + (2) in the code comments?

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"]
        }

Another question: why DomElement.Cq() refers to the whole document and not the current element? How can I make it refer to the current element?

Thanks

도움이 되었습니까?

해결책

Easiest to just let the jQuery methods do the work for you:

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

The Select method always selects against the entire dom, it's analagous to just using $(...) with jQuery. Find selects only from within its context, as in jQuery.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top