How to remove span tag from WebControl when rendered

后端 未结 15 980
生来不讨喜
生来不讨喜 2020-12-31 03:34

When using an ASP.NET CheckBox (and in out case, inherited from a CheckBox) it renders a span around the checkbox input control, this span control

15条回答
  •  滥情空心
    2020-12-31 04:29

    $(document).ready(function() {
      /* remove the relative spam involving inputs disabled */
      $('input[type="checkbox"]').parent('.aspNetDisabled').each(function() {
        var $this = $(this);
        var cssClass = $this.attr('class');
        $this.children('input[type="checkbox"]').addClass(cssClass).unwrap().parent('label[for],span').first().addClass('css-input-disabled');
      });
    });
    /* CSS Example */
    .css-input {
      position: relative;
      display: inline-block;
      margin: 2px 0;
      font-weight: 400;
      cursor: pointer;
    }
    .css-input input {
      position: absolute;
      opacity: 0;
    }
    .css-input input:focus + span {
      box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
    }
    .css-input input + span {
      position: relative;
      display: inline-block;
      margin-top: -2px;
      margin-right: 3px;
      vertical-align: middle;
    }
    .css-input input + span:after {
      position: absolute;
      content: "";
    }
    .css-input-disabled {
      opacity: .5;
      cursor: not-allowed;
    }
    .css-checkbox {
      margin: 7px 0;
    }
    .css-checkbox input + span {
      width: 20px;
      height: 20px;
      background-color: #fff;
      border: 1px solid #ffffd;
      -webkit-transition: background-color 0.2s;
      transition: background-color 0.2s;
    }
    .css-checkbox input + span:after {
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      font-family: "FontAwesome";
      font-size: 10px;
      color: #fff;
      line-height: 18px;
      content: "\f00c";
      text-align: center;
    }
    .css-checkbox:hover input + span {
      border-color: #ccc;
    }
    .css-checkbox-primary input:checked + span {
      background-color: #5c90d2;
      border-color: #5c90d2;
    }
    
    
    
    
    

提交回复
热议问题