0

我在下面有一个按钮:

<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); 
4

3 回答 3

1

你有没有尝试过

$('#submitstudents').on('click', function(){ if(editvalidation()) showConfirm(); });

?

于 2013-03-01T15:18:34.030 回答
0

试试这个:

$('#submitstudents').click(function(){
  if(editvalidation())
    showConfirm();
});
于 2013-03-01T15:20:41.777 回答
0

我以前遇到过这种情况。这段代码一直都很完美:

$('#submitstudents').live('click', function(){
   ...do what ever you want...
});
于 2013-03-01T15:40:27.213 回答