简单jQuery覆盖标签替代方案

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单jQuery覆盖标签替代方案相关的知识,希望对你有一定的参考价值。

Focus and keypress events determine when to hide, show, or dim a label.

Use in tandem with the following html/CSS:


HTML
----

<li>
First Name

</li>


CSS
----


li {
position: relative;
}

label {
position: absolute;
top: 1px;
left: 1px;
cursor: text;
}
  1. $(document).ready(function() {
  2.  
  3. $('input[type=text]').focusin(function () {
  4. $(this).prev('label').css('color','#999');
  5. });
  6.  
  7. $('input[type=text]').focusout(function () {
  8. $(this).prev('label').css('color','#111');
  9. });
  10.  
  11. $('input[type=text]').keydown(function () {
  12. if($(this).attr('value') == '') {
  13. $(this).prev('label').hide();
  14. }
  15. });
  16.  
  17. $('input[type=text]').keyup(function () {
  18. if ($(this).attr('value') == '') {
  19. $(this).prev('label').show();
  20. $(this).prev('label').css('color','#999');
  21. }
  22. });
  23.  
  24. });

以上是关于简单jQuery覆盖标签替代方案的主要内容,如果未能解决你的问题,请参考以下文章

单选按钮覆盖标签

几条jQuery代码片段助力Web开发效率提升

片段的布局被活动的工具栏/标签布局覆盖

CSS中的媒体片段URI替代方案?

Dojo 中 jQuery .css() 的替代方案

inline内联函数