2014-02-22 45 views
0

我有这个脚本的问题。CSS文本对齐属性无法正常工作

输出不与中心对齐;只有红色才能正常工作。

<script>  
    $(document).ready(function() { 
     $("#register_form input").focus(function() { 
      $("#status").fadeOut(800); 
     }); 

     $("#pass1").keyup(function() { 
      if ($(this).val().length < 6) { 
       $("#output_pass1").css("color", "red").css('text-align', 'center').html("<br/><br/>very short "); 

      } 
     }); 
    }); 
</script> 

,这是HTML代码:

<label for="pass1">Password :</label> 
<div class="col-sm-5"> 
    <input type="Password" id="pass1" placeholder="Enter your password " required> 
</div> 

<small id="output_pass1" ></small> 
+0

请显示更多的html代码。 – Akhlesh

+0

我编辑了我的代码 –

+2

你能提供一个小提琴的工作? –

回答

1

请给元素display: block;,太:

small { display: block; } 

$("#output_pass1") 
.css({"color":"red", "text-align":"center", "display": "block" }) 
.html("<br/><br/>very short "); 

小提琴:http://jsfiddle.net/aslancods/NDNYF/5/

+0

问题是由阿斯兰解决,非常感谢你先生! –

+0

不用期待John Low, 谢谢牙刷修正语法错误。 – sudhnk