Delete default value of an input text on click

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

I have an input text :


I want to put a default value like

13条回答
  •  孤城傲影
    2020-11-29 18:46

    Here is very simple javascript. It works fine for me :

    // JavaScript:
    
    function sFocus (field) {
        if(field.value == 'Enter your search') {
            field.value = '';
        }
        field.className = "darkinput";
    }
    
    function sBlur (field) {
        if (field.value == '') {
            field.value = 'Enter your search';
            field.className = "lightinput";
        }
        else {
            field.className = "darkinput";
        }
    }
    // HTML
    

提交回复
热议问题