开发者

how to clear form each specific input field on mouse click on it using jquery

i have form with text inputs having some value i.e. please enter name etc etc. i want when the client clicks on the text field the default text to disappear. i after searchin开发者_如何学运维g added the onclick="this.value=\'\'" but its not clearing please help.


You can use what stackoverflow uses on the search box:

<input onfocus="if (this.value=='search') this.value = ''" type="text" value="search">

Also, here is a question about the same thing: How do I make an HTML text box show a hint when empty?

NOTE: With HTML5 you can use the following:

<input type="email" name="address" placeholder="john@example.net">

http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#attr-input-placeholder


This should do that.

$('#yourFormId').find('input').click(function(){
    $(this).val('');

}

but what you probably actually want is something like the labelOVer plugin: http://remysharp.com/2007/03/19/a-few-more-jquery-plugins-crop-labelover-and-pluck/#labelOver


I recomnded use onfocus with onblur. If client set cursor into field text is hide, but if it does not write to filed - default text is return.

<input type="text" value="search" onfocus="if(this.value=='search') this.value=''" onblur="if(this.value=='') this.value='search'">


Its something like this,

$('#userName').onfocus(function(){
   if($(this).val() === 'User Name'){
    $(this).val('');
 }
})
.onblur(function(){
    if($(this).val() === ''){
        $(this).val('User Name');
     }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜