它下面我有一个按钮:如何获得一个按钮来执行某项功能时,已被点击
<p><button id='submitstudents'>Submit Students</button></p>
我想要的按钮做的是触发editvalidation()
功能,如果传递然后继续与确认。我有jquery代码设置验证,并显示确认,如果验证已通过,但如何获得按钮返回时点击按钮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);
相同的结果为对方回答,没有任何反应,当不正确,如果正确 – user2048994 2013-03-01 15:28:39
@ user2048994是HTML创建的提交按钮没有出现确认没有验证出现,或在DOM通过一些JavaScript?如果是后者,你可能需要为'on'使用稍微不同的语法。 – dunc 2013-03-01 15:36:48
@duncI简单地使用'button' html代码来显示按钮,但是按钮的功能是由DOM中的某个jquery完成的,如你所提到的 – user2048994 2013-03-01 15:38:15