开发者

using jquery focus to empty text fields

开发者 https://www.devze.com 2023-01-24 01:13 出处:网络
I am trying to add focus on the following code, which would loop through 开发者_如何转开发the 10 or more fields and remove the default value(s)whenthe user focuses on the field.

I am trying to add focus on the following code, which would loop through 开发者_如何转开发the 10 or more fields and remove the default value(s) when the user focuses on the field. how can i add the focus to the existing code? -thanks

$(document).ready(function() {  
    $('#tradition').click(function() {
    $('#form-container').attr("class","trade");                         
    $('.lblMadlib11').text("Eleven ");
    $('.lblMadlib11a').val("eleven value field");
});


Assuming this markup this:

Html:

<input type="text" placeholder="default text" />

Javascript:

$(function(){ // onload
    $('input:text').focus(function(){ // onfocus
       if($(this).val() == $(this).attr('placeholder')) // if value is default value
           $(this).val(''); // clear value
    });
});
0

精彩评论

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