我正在尝试编写一些代码,如果输入为空,则输入颜色变为红色。用户键入输入后,红色将被删除。
HTML
<html>
<head>
<!-- add main style -->
<link rel="stylesheet" href="../css/style.css">
<!-- add JQuery -->
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
</head>
<body>
<div class="financeContainer">
<div class="searchBox">
<input id="financeSearch" type="text" class="financeInput" placeholder="Enter The Code">
<button id="financeBtn" class="financeSearchBt"><i class="fas fa-search financeSearchIcon"></i></button>
</div>
</div>
<script>
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
的CSS
.redColor{
color: red;
}
Run Code Online (Sandbox Code Playgroud)
jQuery的
$(document).ready(function () {
$("#financeSearch").keydown(function () {
if ($("#financeSearch").val().length>0){
$("#financeSearch").removeClass("redColor")
}
});
$(document).bind('keypress', function(e) {
if(e.keyCode==13){
$('#financeBtn').trigger('click');
}
});
$("#financeBtn").click(function () {
var financeKey = $("#financeSearch").val();
if (financeKey == ""){ …Run Code Online (Sandbox Code Playgroud) 我正在创建一个简单的注册表单,我的问题是,当我使用strlen函数时,当我输入数字作为密码时它不会显示任何内容,当我输入不是数字时它会显示消息,即使它超过6个字符
<?php
if (isset($_POST['signup'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone-number'];
$address = $_POST['address'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
}
if (isset($password)) {
if (strlen($password < 6)) {
$password_err = "password must be at least 6 characters";
}
}
?>
<?php
if (isset($password_err)){
echo $password_err;
}
?>
Run Code Online (Sandbox Code Playgroud)