Tip Precoz 6: Limpiar valores de input

8/Jun/2010 3249

Esta pequeña función de jQuery me es muy útil cuando tengo un campo de texto (<input>, <textarea>, etc) y éste tiene un valor por defecto (por ejemplo, el Buscar que se ve en el header de este humilde sitio). Cuando hago foco en él para escribir, quiero que ese value desaparezca y el usuario pueda ingresar lo que quiera; caso contrario, si el usuario lo deja vacío o si es el mismo que el original (en este caso, Buscar) vuelve a restablecerse al definido por defecto.

$('input').each(function(){
   // tomamos el valor actual del input
   var currentValue = $(this).val();
   // en el focus() comparamos si es el mismo por defecto, y si es asi lo vaciamos
   $(this).focus(function(){
      if( $(this).val() == currentValue ) {
         $(this).val('');
      };
   });
   // en el blur, si el usuario dejo el value vacio, lo volvemos a restablecer
   $(this).blur(function(){
      if( $(this).val() == '' ) {
         $(this).val(currentValue);
      };
   });
});

Ver ejemplo

Comentarios

  1. 그녀의 손가락을 스토킹에 애널 소녀에 넣어 [#]

    Right here is the right web site for everyone who
    wants to find out about this topic. You know a whole lot
    its almost tough to argue with you (not that I really would want to…HaHa).

    You certainly put a new spin on a topic that’s
    been written about for many years. Wonderful stuff, just
    wonderful!

  2. ์ตรวจหวย [#]

    Hi! Someone in my Myspace group shared this site with us so I came to look it over.
    I’m definitely loving the information. I’m book-marking and
    will be tweeting this to my followers! Great blog and great style and design.

  3. live casino [#]

    Link exchange is nothing else however it is simply placing the other person’s
    webpage link on your page at suitable place and other person will also
    do similar for you.

  4. 우리카지노 [#]

    I could not resist commenting. Well written!

  5. Paulblabs [#]

    pharmacy rx viagra

  6. オンラインカジノ [#]

    You are so awesome! I don’t believe I have read a single thing like this before.
    So great to discover someone with a few original thoughts
    on this issue. Really.. thanks for starting this up. This website is something that’s needed on the web, someone with
    some originality!

  7. GaloInvake [#]

    strep throat zithromax

  8. Titanium earrings [#]

    I like it when people come together and share opinions.
    Great blog, stick with it!

  9. Markblabs [#]

    ivermectin 9 mg

  10. marketing campaign effort [#]

    Yesterday, while I was at work, my sister stole my iphone and tested
    to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My iPad is now destroyed
    and she has 83 views. I know this is totally off topic but I had to
    share it with someone!

  11. ベット365 [#]

    I am in fact thankful to the owner of this website who has shared this enormous post at at this time.

  12. ポーカー [#]

    This website truly has all of the information and facts I wanted about this subject and didn’t know who to
    ask.

  13. Joshuawag [#]

    prescription drug coupons and rebates fresenius lawsuit update 2017 cost of cialis versus viagra buy cialis tablets best price for sildenafil price of viagra at costco

  14. 파라오 카지노 쿠폰 [#]

    I’d like to thank you for the efforts you’ve put
    in penning this blog. I really hope to see the same high-grade content by
    you in the future as well. In truth, your creative writing abilities has motivated me to get my own site now 😉

  15. 점보 카지노 [#]

    Howdy! This article couldn’t be written much better!
    Looking through this article reminds me of my previous roommate!
    He constantly kept talking about this. I most certainly will send this information to
    him. Fairly certain he will have a very good read.
    Thanks for sharing!

  16. Payday loans [#]

    Hello there, just became alert to your blog through Google, and found that it is truly informative.
    I’m gonna watch out for brussels. I will be grateful if you continue this in future.
    Lots of people will be benefited from your writing. Cheers!

  17. ivermectin 12 mg [#]

    Global Low-down Fro this outcome
    https://ivermectinstrom.com ivermectin over the counter
    https://stromectolivermect.com ivermectin tablets over counter
    https://ivermectstromect.com ivermectin tablets for humans
    https://ivermectinst.com ivermectin 6 mg
    https://ivermectinst.com ivermectin 3 mg

  18. relaxing instrumental music [#]

    Thanks for finally talking about > Tip Precoz 6: Limpiar valores de input |
    CSSLab | Laboratorio de ideas web < Loved it!

  19. 우리카지노 [#]

    Nice blog right here! Also your web site quite a bit up fast!

    What host are you the usage of? Can I get your affiliate hyperlink for your host?
    I wish my website loaded up as quickly as yours lol

  20. prednisolonewarnings [#]

    prednisone tablets prednisolone

  21. buy accutane [#]

    isotretinoin isotretinoina

  22. whatismodafinil [#]

    modafinil 200mg provigil for adhd

  23. genesis casino india [#]

    Does your website have a contact page? I’m having trouble locating
    it but, I’d like to shoot you an email. I’ve got some creative ideas for your blog you might be interested in hearing.
    Either way, great site and I look forward to seeing it improve over time.

  24. betting sports [#]

    Hi Dear, are you truly visiting this site
    on a regular basis, if so after that you will without doubt obtain fastidious experience.

  25. 우리카지노 [#]

    I will immediately clutch your rss as I can’t in finding your e-mail subscription link or
    newsletter service. Do you’ve any? Please permit me understand
    in order that I could subscribe. Thanks.

  26. origin gift copy [#]

    Hi there I am so excited I found your blog, I really found you by accident, while I was browsing on Yahoo for something else, Anyways I
    am here now and would just like to say cheers for a fantastic post and a all round thrilling blog (I also love the theme/design), I don’t
    have time to look over it all at the moment but I have bookmarked
    it and also included your RSS feeds, so when I have time I
    will be back to read a lot more, Please do keep up the great work.

  27. viviane petri comendo gostoso에 대한 리뷰 보기 [#]

    This post is actually a good one it helps new the web viewers, who are wishing for blogging.

  28. slot games [#]

    It’s really a cool and useful piece of information. I’m satisfied that you shared this useful information with us.
    Please stay us informed like this. Thanks for sharing.

  29. adult toys [#]

    Hi there, You have done an excellent job. I will certainly digg it and personally suggest to my friends.
    I am confident they’ll be benefited from this website.

  30. Tedblabs [#]

    brand viagra online canadian pharmacy

  31. 10cric login [#]

    Have you ever considered about adding a little bit more
    than just your articles? I mean, what you say is fundamental and all.
    However think of if you added some great pictures or video clips to give
    your posts more, «pop»! Your content is excellent but with pics
    and video clips, this blog could definitely be one of the best in its field.

    Superb blog!

  32. online casinos [#]

    I feel this is among the so much significant
    information for me. And i am satisfied reading your article.

    But should observation on some common issues, The website taste is great, the articles is actually excellent : D.
    Just right task, cheers

  33. 빅카지노 [#]

    Definitely believe that that you stated. Your favorite justification seemed to be on the internet the easiest thing to have in mind of.
    I say to you, I definitely get annoyed at the same time as
    other folks consider worries that they plainly do not realize about.

    You controlled to hit the nail upon the highest and also defined out the whole thing
    with no need side-effects , other folks could take a signal.
    Will likely be again to get more. Thanks

  34. 카지노사이트 [#]

    Greetings! Quick question that’s completely off topic. Do you know how
    to make your site mobile friendly? My web site looks weird when browsing from my apple
    iphone. I’m trying to find a theme or plugin that might
    be able to resolve this problem. If you have any suggestions, please
    share. Thanks!

  35. betway india [#]

    Quality articles or reviews is the secret to attract the visitors to visit the
    web page, that’s what this web site is providing.

  36. buy aged domains [#]

    I like what you guys are usually up too. Such clever work and exposure!
    Keep up the fantastic works guys I’ve added you guys to my personal
    blogroll.

  37. gasoline water pump [#]

    Thank you for sharing your thoughts. I truly appreciate your
    efforts and I am waiting for your next post thanks once again.

  38. 더나인카지노 [#]

    I blog frequently and I really appreciate your information. The article has
    truly peaked my interest. I will bookmark your blog and keep checking for new details about
    once a week. I subscribed to your Feed as well.

  39. tmg industrial parts [#]

    Hey there! I just wanted to ask if you ever have any
    trouble with hackers? My last blog (wordpress) was hacked
    and I ended up losing months of hard work due to
    no back up. Do you have any solutions to protect
    against hackers?

  40. table games [#]

    I got this web page from my buddy who shared with me about this site and now this time I am browsing this web page and reading very informative content at this place.

  41. kèo nhà cái bóng đá việt nam [#]

    I have been surfing online greater than three hours nowadays,
    but I never discovered any interesting article like yours.
    It is pretty price sufficient for me. Personally, if
    all web owners and bloggers made just right content as
    you did, the internet shall be a lot more helpful than ever before.

  42. it professional malpractice [#]

    What’s up colleagues, its wonderful paragraph regarding tutoringand fully
    defined, keep it up all the time.

  43. 바카라사이트 [#]

    It’s awesome designed for me to have a web site,
    which is helpful designed for my knowledge. thanks admin

  44. 온라인 바카라 [#]

    Amazing! This blog looks exactly like my old one! It’s on a totally different subject but it has pretty
    much the same page layout and design. Excellent choice of colors!

  45. Titanium inife [#]

    Wonderful work! That is the kind of information that are supposed to be shared around the net.
    Shame on Google for no longer positioning this submit
    higher! Come on over and consult with my website . Thanks =)

  46. fun88 ฟรี [#]

    hi!,I like your writing so so much! proportion we keep up a correspondence more about your article on AOL?
    I require an expert in this house to resolve my problem.

    Maybe that’s you! Looking forward to look you.

  47. 카지노 추천 [#]

    Wonderful site. Lots of useful information here. I’m sending it to a few friends ans additionally sharing in delicious.
    And of course, thank you to your effort!

  48. 카지노 커뮤니티 [#]

    Everyone loves what you guys are up too. This sort of
    clever work and coverage! Keep up the very good works guys I’ve
    incorporated you guys to blogroll.

CSSLab