Declare a JavaScript function which can hide the label of the calling HTML element

前端 未结 5 1109
猫巷女王i
猫巷女王i 2021-01-29 07:01

HTML


5条回答
  •  日久生厌
    2021-01-29 07:37

    +c.P.u1 jQuery solution can be written in standard JS for modern browsers (IE >=9) as follows

    
    
    
    function label (el) {
      (el = document.querySelector ('label[for=" + el.id + '"]')) && 
        (el.style.display = 'none');
    }
    

    Note that we need to pass the input element as a parameter to the label function.

    The fiddle at http://jsfiddle.net/jstoolsmith/v5kZb/ shows a more structured way of doing this and also replaces the label when the input element loses focus.

提交回复
热议问题