2017-12-05 21 views
-2

は、時刻と日付入力フィールド

$("#tym").keydown(function() { 
 
    if (!($(this).val())) { 
 
    $('#error5').html('<p style="color:red;font-size:14px;"align="center">Enter time</p>'); 
 
    } else { 
 
    $('#error5').html(''); 
 
    } 
 
}); 
 

 
$('#sal').keyup(function() { 
 
    if (!($(this).val())) { 
 
    $('#error6').html('<p style="color:red;font-size:14px;"align="center">Enter salary</p>'); 
 

 
    $('#sal').focus(); 
 

 
    } else { 
 
    $('#error6').html(''); 
 
    } 
 
}); 
 

 
$('#sald').keyup(function() { 
 
    if (!($(this).val())) { 
 
    $('#error7').html('<p style="color:red;font-size:14px;"align="center">Enter Salarydate</p>'); 
 

 
    $('#sald').focus(); 
 

 
    } else { 
 
    $('#error7').html(''); 
 
    } 
 
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
    </br> 
 
    </br> 
 

 

 
    <form method="POST" align="center" id="ins"> 
 
    </br> 
 

 

 
    <label>Available Time:</label> 
 
    <input type="time" name="availabletime" id="tym" /> 
 
    <span id="error5"></span> 
 
    <br/><br/> 
 

 
    <label>Salary:</label> 
 
    <input type="text" name="amount" id="sal" /> 
 
    <span id="error6"></span> 
 
    <br/><br/> 
 

 
    <label>Salary Date:</label> 
 
    <input type="date" name="salarydate" id="sald" /> 
 
    <span id="error7"></span> 
 
    <br/><br/> 
 
    </br> 
 
    <input type="submit" name="submit" value="Enter" /> 
 
    </form>\
のエラーメッセージを非表示に

コンテキスト: これは働いているフォームvalidation.The検証のためのコードですが、私は、時間と日付のエラーメッセージを非表示にしますすべての他のfeilds検証は、エラーメッセージ隠蔽を含めて働いています。関数keydownをmouseupに変更しましたが、作業していません。時間と日付の入力フィールドのkeyupのような関数はありますか?

答えて

0

あなたが入力

$("#tym").on("input", function() { 
    if (!($(this).val())) { 
    $('#error5').html('<p style="color:red;font-size:14px;"align="center">Enter time</p>'); 
    } else { 
    $('#error5').html(''); 
    } 
}); 

を変更した場合、あなたのエラー処理を呼び出します input event使用することができます
関連する問題