当我提交并单击“确定”时,它会继续,但是当我按下"取消"无论如何它提交。我尝试使用此代码但提交和取消按钮仍然执行相同的操作。
model.saveForm = function() {
var r = confirm("Press a button");
alert(p);
if (r == true) {
x = "You pressed OK!";
if (!validateRequiredNew()) return;
model.saving(true);
// check if group id is needed
var generatedGroupIdPromise = null;
// if (model.selectedUsers().length > 1 || model.selectedUsers()[0].selectedRoles().length > 1) {
generatedGroupIdPromise = $.ajax({
url: '../_vti_bin/listdata.svc/GroupIdGeneratorList',
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{Title: 'dummy'}",
processData: false,
dataType: "json"
});
} else if (r == false){
x = "You pressed Cancel!";
}
和aspx页面:
<button data-bind="click: saveForm, visible: !saving()">Submit Request</button>
答案 0 :(得分:3)
只需将public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numberOfStudents = -1;
boolean exception = true;
do {
try {
System.out.print("Enter the number of students");
numberOfStudents = input.nextInt();
exception = false;
} catch (InputMismatchException e) {}
input.nextLine();
} while (exception);
int number = 0;
while (number <= numberOfStudents) {
exception = true;
number++;
System.out.println("Enter student name");
String studentName = input.nextLine();
int grade;
do {
try {
System.out.println("Enter grade");
grade = input.nextInt();
exception = false;
} catch (InputMismatchException e) {}
input.nextLine();
} while (exception);
// input.nextLine();
}
}
或return false;
放入您的方法即可。