我正在爲每個表單字段創建一個表單,如果用戶滿足驗證檢查(即,在字段中輸入內容,在內容中進行選擇關閉複選框等),「所需」類不應再應用於該字段。目前CSS已設置爲檢查驗證。如何使用CSS驗證來更改類的狀態
有沒有簡單的方法來做到這一點?
#myForm {
border: 1px solid grey;
padding: 5px;
width: 600px;
}
label {
font-size: 14px;
font-weight: bold;
display: inline-block;
width: 200px;
text-align: right;
padding-right: 5px;
vertical-align: top;
}
#comments {
width: 250px;
height: 100px;
}
.myDropdown {
width: 250px;
}
input[type=text] {
width: 250px;
}
.centered {
width: 100%;
text-align: center;
}
label.required {
color: red;
}
select.required,
input[type=text].required {
border: 1px solid red;
}
input[type=radio].required {
outline: 1px solid red;
}
.message {
font-weight: bold;
text-align: center;
font-size: 16px;
width: 600px;
}
.alertMessage {
color: red;
}
.successMessage {
color: green;
}
<?php
include_once 'includes/error_reporting.php';
require_once 'includes/form_validation.php';
include 'includes/function_library.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Royal Caribbean Contest Form</title>
<link rel="stylesheet" href="stylesheets/02-27-2017_form.css" />
</head>
<body>
<div id="myForm">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<label for="firstName">Enter your first name:</label>
<input type="text" id="firstName" name="firstName" required value="<?php echo $firstName; ?>">
<br><br>
<label for="lastName">Last Name:</label>
<input type="text" id="lastName" name="lastName" required value="<?php echo $lastName; ?>">
<br><br>
<label for="city">City:</label>
<input type="text" id="city" name="city" required value="<?php echo $city; ?>">
<br><br>
<label for="state">State:</label>
<select id="state" name="state" required>
<option value="">Please select a state...</option>
<?php
getStates($satesArray)
?>
</select>
<br><br>
<label for="preferredDestination">Preferred destination:</label>
<select id="preferredDestination" name="preferredDestination" class="myDropdown">
<option value="">Please select a destination...</option>
<?php
//asort($Destinationarray);// orginases states
getDestinations($Destinationarray);
?>
</select>
<br><br>
<label for="preferredDestination">Comments:</label>
<textarea id="comments" name="comments"><?php echo $comments; ?></textarea>
<br><br>
<label for="emailList">Do you want to be included in our e-mail list?</label>
<input type="radio" value="yes" name="emailList" required>Yes
<input type="radio" value="no" name="emailList" required>No
<br><br>
<div class="centered">
<input type="checkbox" required name="terms" <?php if ($terms) { echo 'checked'; } ?>>I agree with the terms of this contest
</div>
<br><br>
<div class="centered">
<input type="submit" value="Submit entry">
</div>
</form>
</div>
</body>
</html>
PLZ添加'HTML'代碼以及 –
這很難說,因爲你只發布CSS和不工作的例子。另外,對於這樣的問題,即當你有一些工作代碼,但想重構它時,你可以嘗試http://codereview.stackexchange.com/。 –