Warning if required inputs are not selected

前端 未结 1 1427
慢半拍i
慢半拍i 2021-01-27 03:20

How can I add a warning to #printpage when its disabled if its chosen saying please check required fields?

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-27 03:49

    You can use JS function checkValidity(), this will return false if the form is not valid.

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/checkValidity

    isValid = $('.form').checkValidity()
    
    if (!isValid) {
      $('#printpage').innerText = "Please fill in required fields";
      } else {
      $('#printpage').innerText = "";
    }
    

    Your html should contain HTML validity checkers, such as required.

    
    

    0 讨论(0)
提交回复
热议问题