簡體   English   中英

表單-如果設置了占位符,則移動標簽(js)

[英]Form - If placeholder is set move Label (js)

我需要一些表格幫助。

我想要類似此網站的表格:

https://secure.mypass.de/sso/web-fullpage/login?service=https%3A%2F%2Flo.la.welt.de%2Fuser%2Fredirect%3FredirectUrl%3Dhttps%253A%252F%252Fwww.welt。 de%252F%253Fwtrid%253Dcrossdevice.n24.desktop.directhome&wt_eid = 2148165323200346732&wt_t = 1483902148371

他們說,如果設置了占位符,則標簽應移動。 有人可以幫我這個忙,我不知道該怎么辦。

Here is my Demo: http://codepen.io/CRYP3/pen/WRvyxw

試試這個代碼,我沒有檢查它,所以不知道這是否有效:

$(function() {
    $("#username").focusin(function() {
        if($("#username").val().length < 1)
            $("#label").addClass("active");
    });
    $("#username").focusout(function() {
        if($("#username").val().length < 1)
            $("#label").removeClass("active");
    });
});

首先,您需要為標簽設置id ,然后需要一個active類,該類實際上將移動標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM