我有这段代码,当人们将需求字段留空时,我想制作一个警告消息框。
编码:
if (@ is_array($cfields)) {
foreach ($cfields as $cf) {
if (intval($cf['required']) == 1) {
if ($cf['type'] == "text" || $cf['type'] == "textarea" || $cf['type'] == "date") {
?>
if(!vrvar.vrcf<?php echo $cf['id']; ?>.value.match(/\S/)) {
document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000';
return false;
}else {
document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='';
}
<?php
}elseif ($cf['type'] == "select") {
?>
if(!vrvar.vrcf<?php echo $cf['id']; ?>.value.match(/\S/)) {
document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000';
return false;
}else {
document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='';
}
<?php
} elseif ($cf['type'] == "checkbox") {
//checkbox
?>
if(vrvar.vrcf<?php echo $cf['id']; ?>.checked) {
document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='';
}else {
document.getElementById('vrcf<?php echo $cf['id']; ?>').style.color='#ff0000';
return false;
}
<?php
}
}
}
}
?>
现在,当该字段为空时,文本仅变为红色。
有任何想法吗?:)