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;
}

showConfirm():

         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 に答える