How to clear text field on focus of text field

前端 未结 9 1999
悲&欢浪女
悲&欢浪女 2020-12-29 12:15

I want to clear the text field when the user clicks on that

9条回答
  •  灰色年华
    2020-12-29 12:49

    This is how I use it for a temperature converter/calculator - when the user types (keyup), the text input box calculates using the assigned function; when the user selects the other text input (there are only two inputs), the selected text input will clear.

    HTML:

    Input:


    Result:

    JavaScript:

    function Conversion() {
        var tempCels = parseFloat(document.getElementById('celsius').value);
          tempFarh =(tempCels)*(1.8)+(32);
          document.getElementById('fahrenheit').value= tempFarh;
     }
    
    function Conversion2() {
        var tempFarh = parseFloat(document.getElementById('fahrenheit').value);
          tempCels =(tempFarh - 32)/(1.8);
          document.getElementById('celsius').value= tempCels;
     }
    

提交回复
热议问题