当管理员选择“处理”时,我试图让表单发出警告。从下拉菜单中读取"您确定要处理吗?"。还有一些代码可以验证“过程”和“过程”。或者'拒绝'已被选中。当管理员点击“拒绝”时,不会发生任何事情。这就是我到目前为止所做的。
<link href="Styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="datatables.min.css">
<script type="text/javascript" src="datatables.min.js"></script>
<script>
$(document).Check(function () {
$("#ToBeProcessed").change(function () {
if ($(this).val() == "Process") {
alert("Are you sure you want to process?");
}
elseif ($(this).val() == "") {
}
alert("You must process or reject the changes to this invoice.");
return false;
});
});
</script>
</head>
<body>
<cfform name="ToBeProcessed" id="ToBeProcessed" action="ToBeProcessed.cfm?Invoice=#Invoice#" preservedata="yes" method="post">
<cfoutput>
<table>
<tr>
<td>
Approved By:
</td>
<td>
#qryGetToBeProcessed.Approved_Username#
</td>
</tr>
<tr>
<td>
Approved Date:
</td>
<td>
#DateFormat(qryGetToBeProcessed.Approved_Date,"MM/DD/YYYY")#
</td>
</tr>
<tr>
<td>
To Be Processed:
</td>
<td>
<cfselect name="ToBeProcessed" id="ToBeProcessed" style="Padding: 2px;" onchange="Check()">
<option value="">Select</option>
<option value="Process">Process</option>
<option value="Rejected">Rejected</option>
</cfselect>
</td>
</tr>
<tr>
<td align="right" colspan="2" style="Padding:3px;">
<cfinput type="Submit" name="Submit" value="Save">
<input type="Button" name="Back" value="Cancel" onclick="window.history.back()">
</td>
</tr>
</table>
</cfoutput>
</cfform>
</body>
答案 0 :(得分:1)
你的问题在这里:
elseif ($(this).val() == "") {
Javascript中没有elseif
。您可能会收到JS错误。检查您的控制台,然后将其更改为:
else if ($(this).val() == "") {
请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else#Using_else_if
此外看起来你还有另一个语法错误,在那个elseif之后还有一个结束}
,这也会导致你出错:
elseif ($(this).val() == "") {
} <--- WHAT'S THIS HERE FOR?
alert("You must process or reject the changes to this invoice.");
这是一个应该有效的重写:
$(document).ready(function () {
$("#ToBeProcessed").on('change', function () {
if ($(this).val() == "Process") {
alert("Are you sure you want to process?");
}
else if ($(this).val() == "") {
alert("You must process or reject the changes to this invoice.");
}
});
});
...您应该能够从onchange="Check()"
中移除<cfselect>
,因为jQuery .on('change')
应该涵盖这一点。