Jquery淡出和淡出仅一次

Jquery淡出和淡出仅一次,jquery,html,Jquery,Html,我在下面输入淡出和淡出用户名 <p> <input type="text"> <span id="xxspan1" style="display: none">Username</span> </p> <script> $("input").focus(function () { $(this).next('#xxspan1').css("display", "inline").fadeO

我在下面输入淡出和淡出用户名

<p>
    <input type="text"> <span id="xxspan1" style="display: none">Username</span>
</p>


<script>
    $("input").focus(function () {
        $(this).next('#xxspan1').css("display", "inline").fadeOut(1000);
        $(this).next('#xxspan1').fadeIn(2000);


    });
</script>

用户名

$(“输入”).focus(函数(){ $(this).next('#xxspan1').css(“display”,“inline”).fadeOut(1000); $(this).next('xxspan1').fadeIn(2000); });
我不想在第二次对焦时淡出淡出,我只想淡出淡出淡出一次

最好的方法是什么?

用于此目的。它将事件附加到只执行一次的元素

$("input").one("focus",function () {
        $(this).next('#xxspan1').css("display", "inline").fadeOut(1000);
        $(this).next('#xxspan1').fadeIn(2000);


    });
试试这个

$("input").on("focus",function (event) {
    $(this).next('#xxspan1').css("display", "inline").fadeOut(1000);
    $(this).next('#xxspan1').fadeIn(2000);
    $( this ).off( event );
});

第一次之后你想要什么?