If input value is blank, assign a value of “empty” with Javascript

后端 未结 6 1383
庸人自扰
庸人自扰 2021-02-01 21:49

So I have an input field, if it\'s blank, I want its value to be the words \"empty\", but if there is any value inputted, I want the value to be the inputted value. I want to us

6条回答
  •  鱼传尺愫
    2021-02-01 22:48

    You can do this:

    var getValue  = function (input, defaultValue) {
        return input.value || defaultValue;
    };
    

提交回复
热议问题