我在javascript中创建了此功能,以便在点击ahref
链接时
$(document).ready(function() {
$("#ProcessCharges").click(function() {
alert("testing");
if($("#customerbilling_unitprice").val() == "") {
alert("Please Enter a Unit Price");
return false;
}
if($("#customerbilling_resellercost").val() == "") {
alert("Please Enter a Reseller Unit Price");
return false;
}
if($("#customerbilling_todate").val() == "") {
alert("Please Enter a To Date");
return false;
}
if($("#customerbilling_fromdate").val() == "") {
alert("Please Enter a From Date");
return false;
}
//work out number of days between the two dates
var tDate = new Date($("#customerbilling_todate").val());
var fDate = new Date($("#customerbilling_fromdate").val());
var diff=tDate-fDate;
var days_between= diff / 1000 / 60 / 60 / 24;
//do the cost per month times 12 (months)
var year_cost = $("#customerbilling_unitprice").val() * 12;
// RESELLER //
var year_cost_reseller = $("#customerbilling_resellercost").val() * 12;
// RESELLER //
//do the yearly cost / 365
//this will give the daily cost
var daily_cost = year_cost / 365;
// RESELLER //
var daily_cost_reseller = year_cost_reseller / 365;
// RESELLER //
//check number of days
alert(days_between);
if(days_between == '29' or days_between == '30' or days_between == '31' or days_between == '0') {
//its a FULL month
var total_cost = parseFloat( $("#customerbilling_unitprice").val().toFixed(2) );
// RESELLER //
var total_cost_reseller = parseFloat( $("#customerbilling_resellercost").val().toFixed(2) );
// RESELLER //
} else {
//now do the daily cost times cost_per_month
var total_cost = daily_cost * days_between;
var total_cost = parseFloat( total_cost.toFixed(2) );
// RESELLER //
var total_cost_reseller = daily_cost_reseller * days_between;
var total_cost_reseller = parseFloat( total_cost_reseller.toFixed(2) );
// RESELLER //
}
$("#customerbilling_unitprice").val(total_cost);
$("#customerbilling_resellercost").val(total_cost_reseller);
});
});
但是当点击链接时,该功能没有运行。它应该做的第一件事是显示它没有做的警告框
我在这里创建了一个小提琴来显示完整的代码:http://jsfiddle.net/0v02nLnc/
答案 0 :(得分:0)
您使用的语法不正确。 替换你的病情
if(days_between == '29' or days_between == '30' or days_between == '31' or days_between == '0') {
到
if(days_between == '29' || days_between == '30' || days_between == '31' || days_between == '0') {
答案 1 :(得分:0)
if(days_between == '29' or days_between == '30' or days_between == '31' or days_between == '0') {
应更改为
if(days_between == '29' || days_between == '30' || days_between == '31' || days_between == '0') {