在CSS状态Bootstrap之间切换

时间:2014-01-27 13:05:05

标签: javascript jquery twitter-bootstrap text input

我在这里有一个引导输入:

<div class="form-group input-group has-warning col-lg-2" id="state">
      <input type="text" class="form-control" name='user' id="inputWarning" width='60' autofocus maxlength=20 required onblur="check()">
      <span class="input-group-addon" id="loadingCheck">✔</span>
</div>

我想在ajax响应时更改其验证。可能吗?

2 个答案:

答案 0 :(得分:1)

是的,您可以使用.removeClass().addClass()

<强> HTML

<div class="form-group input-group has-warning col-lg-2" id="state">
      <input type="text" class="form-control" name='user' id="inputWarning" width='60' autofocus maxlength=20 required onblur="check()">
      <span class="input-group-addon" id="loadingCheck"></span>
</div>

<强> JS

$(document).ready(function(){
   $('div').removeClass('has-warning');
   $('div').addClass('has-success');
});

更新

$(document).ready(function(){
    var a = $('div');
    if(a.hasClass('has-warning') || a.hasClass('has-error')){
       a.removeClass('has-warning');
       a.removeClass('has-error'); 
       a.addClass('has-success');
    }
});

<强> FIDDLE

答案 1 :(得分:0)

在check()AJAX响应中尝试$( "#state" ).removeClass( "has-warning" )