我有4个字段的html表单,1)部门2)电话3)员工4)日期。因此,如果用户按下 save_department_number 按钮而不在字段上输入任何内容,我可以使用jquery / ajax显示错误消息。
但现在我想显示一条警告消息 WHEN 所有字段/字段都不为空但用户忘记点击 save_department_button 按钮。我怎么能用JQuery / Javascript做到这一点?
这是我的html表单
<div id="column3">
<form id="save_department">
<table border="0" width="520">
<div id="success"></div>
<tr>
<td colspan="1" valign="top"><b>Add Department Number <hr></b></td>
<td colspan="1" align="right"><a id="addmore">Add more (+)</a> </td>
<td colspan="2" valign="top" align="right" width="170"><input type="submit" class="search_submit" value="Save Department Number"><input type="hidden" name="cid" value="<?php echo $cid; ?>"></td>
</tr>
</table>
<div class="department_box">
<table border="0" width="510">
<tr>
<td valign="top" width="135"><b>Department</b></td>
<td valign="top" width="135"><b>Phone</b></td>
<td valign="top" width="75"><b>Employees</b></td>
<td valign="top"><b>Date</b></td>
</tr>
<?php
$depart_row_check = mysqli_query($link, "SELECT * FROM company_department WHERE cid = '$cid' ");
$num_depart_row_check = mysqli_num_rows($depart_row_check);
if($num_depart_row_check == 0){
?>
<tr id="clone">
<td><input type="text" name="department[]" class="medium" id="department" value="" placeholder="department"><input type="hidden" name="new[]" value="new" /></td>
<td><input type="text" name="phone[]" class="medium" id="phone" value="" placeholder="phone"></td>
<td><input type="text" name="employee[]" class="small" id="employee" value="" placeholder="employees"></td>
<td><input type="text" disabled="disabled" value="" class="date" placeholder="date"></td>
</tr>
<?php
}else{
$depart_row_check = mysqli_query($link, "SELECT * FROM company_department WHERE cid = '$cid' ");
while($fetch_department = mysqli_fetch_array($depart_row_check)){
$department_d = stripslashes($fetch_department['department']);
$phone_d = stripslashes($fetch_department['phone']);
$employee_d = stripslashes($fetch_department['employee']);
$updated_d = stripslashes($fetch_department['updated']);
$com_d_id = (int) $fetch_department['com_d_id'];
?>
<tr id="clone">
<td><input type="text" name="department[]" class="medium" id="department" value="<?php echo $department_d; ?>" placeholder="department">
<input type="hidden" name="existing[]" value="<?php echo $com_d_id; ?>" /></td>
<td><input type="text" name="phone[]" class="medium" id="phone" value="<?php echo $phone_d; ?>" placeholder="phone"></td>
<td><input type="text" name="employee[]" class="small" id="employee" value="<?php echo $employee_d; ?>" placeholder="employees"></td>
<td><input type="text" disabled="disabled" class="date" value="<?php echo $updated_d; ?>" placeholder="date"></td>
</tr>
<?php
}
}
?>
<div class="apendto"></div>
</table>
</div>
</form>
可能是可以使用此方法完成但无法完成它:
$(document).ready(function(){
$(document).click(function(e){
if ($(e.target).is('#save_department,#save_department *')) {
return;
}
else
{
alert("Hi");
}
});
});