我遇到的问题是,我无法获取event.preventDefault()来阻止表单在嵌套if语句下的嵌套if语句中针对父票证对原始票证进行测试(按预期工作)。似乎失去了调用事件处理程序的能力。我尝试过返回false,event.stopPropagation(),event.stopImmediatePropagation(),并且在嵌套条件内没有任何效果。有人可以帮我一下吗?
$( "#editTicket" ).submit(function( event ) {
var inputTicket = $('input[name=parentTicketID]').val();
var orginalTicketID = $('input[name=id]').val();
// Parent Ticket cannot be the original ticket
if ( inputTicket == orginalTicketID )
{
$("#parentTicketMessage").html("The parent ticket number is the same the original ticket. Please change the parent ticket number.");
$('input[name=parentTicketID]').focus();
event.preventDefault();
}
if ( inputTicket != orginalTicketID && inputTicket.length > 0)
{
$.get("/resources/cfc/qmdata/ticket.cfc?method=getTicketArray&returnformat=json",{id:inputTicket}).done(function(data)
{
var thisTicketID = JSON.parse(data);
if ( thisTicketID.toString().length == 0 )
{
alert("inside bad ticket");
$("#parentTicketMessage").html("This is not a valid ticket number. Please change the parent ticket number.");
$('input[name=parentTicketID]').focus();
event.preventDefault();
}
else if (thisTicketID[0].ticketID.toString().length > 0 && thisTicketID[0].parentTicketID.toString().length > 0)
{
$.get("/resources/cfc/qmdata/ticket.cfc?method=getTicketArray&returnformat=json",{parentTicketID:inputTicket}).done(function(data2)
{
var thisParentTicketID = JSON.parse(data2);
// We need to check to see if the parentTicketID has not been used on this page.
if (thisParentTicketID.toString().length != 0 && thisParentTicketID[0].ticketID != inputTicket)
{
alert("already used");
// This is the child ticket check and is already being used...stop processing and display message
$("#parentTicketMessage").html("This ticket number is already a child ticket and cannot be used."); $('input[name=parentTicketID]').focus();
event.preventDefault();
}
});
};
});
}
});
'''
我要完成的工作只是简单地在满足某些条件时在表单中添加一条消息,并停止发布表单,直到用户解决问题为止。