Delete default value of an input text on click

前端 未结 13 1987
逝去的感伤
逝去的感伤 2020-11-29 18:24

I have an input text :


I want to put a default value like

13条回答
  •  借酒劲吻你
    2020-11-29 19:03

    Here is an easy way.

    #animal represents any buttons from the DOM.
    #animal-value is the input id that being targeted.

    $("#animal").on('click', function(){
        var userVal = $("#animal-value").val(); // storing that value
        console.log(userVal); // logging the stored value to the console
        $("#animal-value").val('') // reseting it to empty
    });
    

提交回复
热议问题