我在下面有一个按钮:
<p><button id='submitstudents'>Submit Students</button></p>
我想要按钮做的是触发该editvalidation()
功能,如果通过了,则继续进行确认。我已经为验证设置了 jquery 代码,并在验证已通过时显示确认,但是如何让按钮返回单击的editvalidation()
whenc?
下面是相关的jquery代码:
编辑验证():
function editvalidation()
{
if ($("#coursesDrop").val()==""){
$("#courseAlert").html("Please Select a Course from the Course Drop Down Menu");
}
if ($("#coursesDrop").val()!="" && $("#courseadd").children().length==0){
$("#courseAlert").html("You have not Selected any Students you wish to Add into Course");
}
if ($("#coursesDrop").val()!="" && $("#courseadd").children().length!=0){
return true;
}
return false;
}
显示确认():
function showConfirm(){
var courseNoInput = document.getElementById('currentCourse').value;
var courseNameInput = document.getElementById('currentCourseName').value;
if (editvalidation()) {
var confirmMsg=confirm("Are you sure you want to add your selected Students to this Course:" + "\n" + "Course: " + courseNoInput + " - " + courseNameInput);
if (confirmMsg==true)
{
submitform();
}
}
}
当前甚至检查按钮的点击:
$('body').on('click', '#submitstudents', showConfirm);