开发者

Background text in textbox

I want to display a background text in the textbox.

ex: The T开发者_如何学Pythonitle textbox in the stackoverflow Ask question page.

Needs: If i enter some text inside the textbox it should disappear.

Geetha.


A good link is http://attardi.org/labels as referenced here https://stackoverflow.com/questions/781473/how-to-create-a-label-inside-an-input-element


You need to use javascript for the same.

Use following two functions in javascript and it is done.

        function clearDefault(obj,val)
        {
            objInput=document.getElementById(obj);
            if(objInput.value==val)
            {
                objInput.value="";
            }
        }
        function setDefault(obj,val)
        {
            objInput=document.getElementById(obj);
            if(objInput.value=="")
            {
                objInput.value=val;
            }
        }

You need to apply it on your code by using two javascript events as follow.

    <input name="email" type="text" class="textbox" id="email" 
  value="Email" size="12" onfocus="clearDefault('email','Email');" 
  onblur="setDefault('email','Email');"/>

So when you control get focus it the default text will be cleared. Ant That's it.

Hope this will help!


Well, since you put jquery as a tag for the question, I assume you're already using jquery for your project. In that case, here's a neat plugin that does the trick: Labelify. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜