当前位置: 首页>>代码示例>>C#>>正文


C# CQ.Remove方法代码示例

本文整理汇总了C#中CsQuery.CQ.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# CQ.Remove方法的具体用法?C# CQ.Remove怎么用?C# CQ.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsQuery.CQ的用法示例。


在下文中一共展示了CQ.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReplaceWith

        /// <summary>
        /// Replace each element in the set of matched elements with the provided new content.
        /// </summary>
        ///
        /// <param name="content">
        /// The HTML string of the content to insert.
        /// </param>
        ///
        /// <returns>
        /// The current CQ object
        /// </returns>
        ///
        /// <url>
        /// http://api.jquery.com/replaceWith/
        /// </url>

        public CQ ReplaceWith(params string[] content)
        {
            if (Length > 0)
            {
                // Before allows adding of new content to an empty selector. To ensure consistency with jQuery
                // implentation, do not do this if called on an empty selector. 

                // The logic here is tricky because we can do a replace on disconnected selection sets. This has to
                // track what was orignally scheduled for removal in case the set changes in "Before" b/c it's disconnected.

                CQ newContent = EnsureCsQuery(MergeContent(content));
                CQ replacing = new CQ(this);

                Before(newContent);
                SelectionSet.ExceptWith(replacing);
                replacing.Remove();

            }
            return this;
        }
开发者ID:sahilpopli,项目名称:CsQuery,代码行数:36,代码来源:ReplaceWith.cs

示例2: Contents

        public void Contents()
        {
           
            Assert.AreEqual(jQuery("#ap").Contents().Length, 9, "Check element contents" );
            Assert.IsTrue( jQuery("#iframe").Length>0, "Check existence of IFrame document" );

            jQuery("#loadediframe").Append(@"<html>
              <head>
                <title>iframe</title>
              </head>
              <body>
                <div><span>span text</span></div>
              </body>
            </html>");
            
            var ibody = jQuery("#loadediframe").Contents().Find("body");
            Assert.IsTrue( ibody.Length>0, "Check existance of IFrame body" );
            var csq = new CQ("span", ibody);
            Assert.AreEqual(csq.Text(), "span text", "Find span in IFrame and check its text" );

            jQuery(ibody).Append("<div>init text</div>");
            csq = new CQ("div", ibody);
            Assert.AreEqual(csq.Length, 2, "Check the original div and the new div are in IFrame" );
            csq = new CQ("div:last", ibody);
            Assert.AreEqual(csq.Text(), "init text", "Add text to div in IFrame" );

            csq = new CQ("div:last", ibody);
            csq.Text("div text");
            Assert.AreEqual(new CQ("div:last", ibody).Text(), "div text", "Add text to div in IFrame");

            csq = new CQ("div:last", ibody).Remove();
            Assert.AreEqual(jQuery("div",ibody).Length, 1, "Delete the div and check only one div left in IFrame" );

            Assert.AreEqual(jQuery("div",ibody).Text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );

            csq = new CQ("<table/>", ibody);
            csq.Append("<tr><td>cell</td></tr>").AppendTo(ibody);
            csq = new CQ("table", ibody);
            csq.Remove();
            csq = new CQ("div", ibody);
            Assert.AreEqual(csq.Length, 1, "Check for JS error on add and delete of a table in IFrame" );

            // using contents will get comments regular, text, and comment nodes
            var c = jQuery("#nonnodes").Contents().Contents();
            Assert.AreEqual(c.Length, 1, "Check node,textnode,comment contents is just one" );
            Assert.AreEqual(c[0].NodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
        }
开发者ID:kaleb,项目名称:CsQuery,代码行数:47,代码来源:Traversing.cs


注:本文中的CsQuery.CQ.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。