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


C# IHtmlElement.RemoveAttribute方法代码示例

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


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

示例1: BindElement

    /// <summary>
    /// 对元素进行数据绑定
    /// </summary>
    /// <param name="element">需要绑定数据的元素</param>
    /// <param name="context">绑定上下文</param>
    /// <returns>返回是否对元素进行了不可逆转的操作(例如移除),故而禁止后续的绑定操作</returns>
    public void BindElement( HtmlBindingContext context, IHtmlElement element )
    {

      if ( element.Attribute( "binding-visible" ) != null )
      {
        var visible = element.Attribute( "binding-visible" ).Value();
        if ( visible.EqualsIgnoreCase( "false" ) || visible.EqualsIgnoreCase( "hidden" ) || visible.EqualsIgnoreCase( "invisible" ) )
        {
          element.Remove();

          context.CancelChildsBinding = context.BindCompleted = true;
        }
      }





      {
        //处理样式类
        var classAttribute = element.Attribute( classAttributePrefix );
        if ( classAttribute != null )
        {
          if ( !string.IsNullOrWhiteSpace( classAttribute.AttributeValue ) )
          {

            var classes = Regulars.whiteSpaceSeparatorRegex.Split( classAttribute.AttributeValue ).Where( c => c != "" ).ToArray();
            if ( classes.Any() )
              element.Class( classes );
          }

          element.RemoveAttribute( classAttributePrefix );
        }

      }

      {
        var classAttributes = element.Attributes().Where( a => a.Name.StartsWith( classAttributePrefix ) ).ToArray();
        BindElementClasses( element, classAttributes );
      }

      //处理CSS样式
      var styleAttributes = element.Attributes().Where( a => a.Name.StartsWith( styleAttributePrefix ) ).ToArray();
      BindElementStyles( element, styleAttributes );
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:51,代码来源:StyleBinder.cs

示例2: ProcessActionLink

    /// <summary>
    /// 派生类重写此方法对拥有 Action URL 的元素进行处理
    /// </summary>
    /// <param name="element">要处理的元素</param>
    /// <returns>元素是否包含 Action URL 并已经进行处理。</returns>
    protected virtual bool ProcessActionLink( IHtmlElement element )
    {
      if ( element.Attribute( "action" ) == null )
        return false;

      string attributeName;

      if ( element.Name.EqualsIgnoreCase( "a" ) )
        attributeName = "href";

      else if ( element.Name.EqualsIgnoreCase( "img" ) || element.Name.EqualsIgnoreCase( "script" ) )
        attributeName = "src";

      else if ( element.Name.EqualsIgnoreCase( "form" ) && element.Attribute( "controller" ) != null )
        attributeName = "action";

      else
        return false;



      var action = element.Attribute( "action" ).Value() ?? RouteData.Values["action"].CastTo<string>();
      var controller = element.Attribute( "controller" ).Value() ?? RouteData.Values["controller"].CastTo<string>();


      var routeValues = UrlHelper.GetRouteValues( element );


      element.RemoveAttribute( "action" );
      element.RemoveAttribute( "controller" );
      element.RemoveAttribute( "inherits" );


      var url = UrlHelper.Action( action, controller, routeValues );

      if ( url == null )
        element.Attribute( attributeName ).Remove();

      else
        element.SetAttribute( attributeName, url );


      return true;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:49,代码来源:ActionUrlBinder.cs

示例3: GetRouteUrl

        /// <summary>
        /// 从元素标签中获取路由的虚拟路径
        /// </summary>
        /// <param name="element">要获取分析路由虚拟路径的元素</param>
        /// <param name="clearRouteAttributes">是否清理路由属性设置</param>
        /// <returns>获取的虚拟路径</returns>
        internal string GetRouteUrl( IHtmlElement element, bool clearRouteAttributes )
        {
            if ( element == null )
            throw new ArgumentNullException( "element" );

              if ( element.Attribute( "action" ) == null )
            throw new InvalidOperationException();

              var action = element.Attribute( "action" ).Value() ?? RouteData.Values["action"].CastTo<string>();
              var controller = element.Attribute( "controller" ).Value() ?? RouteData.Values["controller"].CastTo<string>();

              var routeValues = GetRouteValues( element, clearRouteAttributes );

              if ( clearRouteAttributes )
              {
            element.RemoveAttribute( "action" );
            element.RemoveAttribute( "controller" );
            element.RemoveAttribute( "inherits" );
              }

              return Url.Action( action, controller, routeValues );
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:28,代码来源:JumonyUrlHelper.cs

示例4: BindElement

        /// <summary>
        /// 对元素进行数据绑定
        /// </summary>
        /// <param name="element">需要绑定数据的元素</param>
        /// <param name="context">绑定上下文</param>
        /// <param name="dataContext">数据上下文</param>
        /// <returns>是否进行了绑定</returns>
        public bool BindElement( IHtmlElement element, HtmlBindingContext context, out object dataContext )
        {
            dataContext = null;

              if ( element.Attribute( "binding-visible" ) != null )
              {
            var visible = element.Attribute( "binding-visible" ).Value();
            if ( visible.EqualsIgnoreCase( "false" ) || visible.EqualsIgnoreCase( "hidden" ) || visible.EqualsIgnoreCase( "invisible" ) )
              element.Remove();
            return true;
              }

              //处理样式类
              {
            var classAttribute = element.Attribute( classAttributeName );
            if ( classAttribute != null )
            {
              if ( !string.IsNullOrWhiteSpace( classAttribute.AttributeValue ) )
              {

            var classes = Regulars.whiteSpaceSeparatorRegex.Split( classAttribute.AttributeValue ).Where( c => c != "" ).ToArray();
            if ( classes.Any() )
              element.Class( classes );
              }

              element.RemoveAttribute( classAttributeName );
            }
              }

              //处理CSS样式
              var styleAttributes = element.Attributes().Where( a => a.Name.StartsWith( styleAttributePrefix ) ).ToArray();
              if ( styleAttributes.Any() )
            BindElementStyles( element, styleAttributes );

              if ( !element.Name.EqualsIgnoreCase( "view" ) && !element.Name.EqualsIgnoreCase( "binding" ) )
              {
            var dataContextExpression = AttributeExpression.ParseExpression( element.Attribute( "datacontext" ) );
            if ( dataContextExpression != null )
              dataContext = GetDataObject( dataContextExpression, context );

            return false;
              }

              var expression = new AttributeExpression( element );

              object dataObject = GetDataObject( expression, context );

              if ( dataObject == null )
            return false;

              var format = element.Attribute( "format" ).Value();

              //绑定到客户端脚本对象
              var variableName = element.Attribute( "var" ).Value() ?? element.Attribute( "variable" ).Value();
              if ( variableName != null )
              {

            if ( format != null )
              dataObject = string.Format( format, dataObject );

            var hostName = element.Attribute( "host" ).Value();

            var script = (string) null;

            if ( hostName == null )
              script = string.Format( "(function(){{ this['{0}'] = {1} }})();", variableName, ToJson( dataObject ) );

            else
              script = string.Format( "(function(){{ this['{0}'] = {1} }})();", variableName, ToJson( dataObject ) );

            element.ReplaceWith( string.Format( "<script type=\"text/javascript\">{0}</script>", script ) );
            return true;
              }

              //绑定为 HTML 文本
              var bindValue = string.Format( format ?? "{0}", dataObject );

              var attributeName = element.Attribute( "attribute" ).Value() ?? element.Attribute( "attr" ).Value();
              if ( attributeName != null )
              {
            var nextElement = element.NextElement();
            if ( nextElement == null )
              return false;

            nextElement.SetAttribute( attributeName, bindValue );
            return true;
              }

              element.ReplaceWith( bindValue );
              return true;
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:98,代码来源:DefaultElementBinder.cs


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