繁体   English   中英

单击按钮后如何获得执行功能的按钮

[英]How to get a button to perform a function when it has been clicked

我在下面有一个按钮:

<p><button id='submitstudents'>Submit Students</button></p>

我想要按钮执行的操作是触发editvalidation()函数,如果传递了该函数,则继续进行确认。 我已经为验证设置了jquery代码,用于显示验证是否通过验证的确认,但是当单击editvalidation()如何获得返回return editvalidation()按钮?

以下是相关的jQuery代码:

editvalidation():

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

你有没有尝试过

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

尝试这个:

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

我以前遇到过 该代码始终有效:

$('#submitstudents').live('click', function(){
   ...do what ever you want...
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM