简体   繁体   中英

Label behind the textbox

I am using the following sample to display text in the background of the textbox. It is working fine too. http://attardi.org/labels/

Problem:

I want to increase the text box with. The box looks like it expanded but while typing the actual size is not expanded. I want to type text till 600px.

Geetha.

$(".input :input").keypress(function(){
    var o = $(this); 
    var s = $("<span></span>").html(o.val()).addClass('placeholder').css('left', '-9999px'); 
    if (o.outerWidth() < 600) {
        o.parent().append(s); 
        if (s.outerWidth() > o.outerWidth()){
            o.css("width", s.outerWidth()); 
        }
        $("span.placeholder").remove();
    }
});

I tested this and it seems to work pretty good. not bad for 7 minutes of code/test/burn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM