我必须开发一个预订电影票网站的模块。该模块应包含以下页面:
预订机票页面 - 这将包含用户输入的预订火车票的详细信息
感谢您的页面 - 用户成功预订门票后会显示感谢页面
票价应根据以下逻辑计算。 (使用Java脚本进行计算)。
票价票价=票价*票价o假设1张票的票价是200。
·儿童票价为100票。
·用户提交表格后,应计算机票价格并在警告框中显示为“您的大致机票金额为INR”。
用于计算票价的JavaScript方法应返回布尔值。
示例:没有门票:4没有孩子:1然后票价将是700.
的application.js:
function myEvaluate()
{
if(document.myForm.tickets.value < document.myForm.childrens.value)
{
window.alert("No of tickets should be greater than the no of children");
document.myForm.children.focus();
return false;
}
var today = new Date().toISOString().split('T')[0];
var ipStr = document.myForm.showdate.value;
var ip = new Date(ipStr).toISOString().split('T')[0];
if(ip<today)
{
window.alert("Show date and time should be either current date or future
date");
document.myForm.showdate.focus();
return false;
}
var totalTix = document.myForm.tickets.value;
var childTix = document.myForm.childrens.value;
var adultTix = totalTix - childTix;
var totalFare = (adultTix*200) + (childTix*100);
alert("Your approximate ticket amount is "+totalFare+ "INR");
return (true);
}
我收到错误:
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告:遇到过时的内容类型:'text / javascript'。 testWeb(htmlpackage.WebTestAssign2):提供了所有输入 正确,但票证计算错误或javaScript method没有返回任何布尔值
答案 0 :(得分:0)
我想问题是您编码的编辑器。
试试这个
function validate()
{
var z=document.forms["myForms"]["showdate"].value;
var x=document.forms["myForms"]["tickets"].value;
var y=document.forms["myForms"]["childrens"].value;
if(y>x)
{
alert("No of tickets should be greater than the no of children");
}
var date=z.substring(0,2);
var month=z.substring(3,5);
var year=z.substring(6,10);
var myDate=new Date(year,month-1,date);
var today= new Date();
if(myDate>today)
{
alert("Show date and time should be either current date or future date");
}
return false;
}
function ticketprice()
{
var x=document.forms["myForms"]["tickets"].value;
var y=document.forms["myForms"]["childrens"].value;
var ticketfare=(x*200)-(y*100);
alert("Your approximate ticket amount is "+ticketfare+" INR");
return true;
}