안녕하세요. 예를 들어 사용자에게 묻는 onclick 이벤트가있는 HTML 양식이 있습니다. 확실한 경우 예/아니오. 아니요를 선택하면 양식 제출을 중단한다고 가정하지만 대화 상자가 비동기로 호출됨에 따라 처리하는 것처럼 보입니다. 내 프롬프트를 표시하기 위해 jquery 플러그인 http://marcosesperon.es/apps/messi/을 사용하고 있습니다. 내가 ASP.NET MVC 4와 I '를 사용하고html 양식 제출 중지
<script>
var COMMAND = {
SAVE: { value: 0, name: "Save", tense: "saved" },
EMAIL: { value: 1, name: "Email", tense: "emailed" },
SUBMIT: { value: 2, name: "Submit", tense: "submitted" },
};
function processCommand(command) {
if (command == COMMAND.EMAIL) {
}
else if (command == COMMAND.SAVE) {
$('#Submit').val(command.name);
$('#inspectionForm').submit();
}
else if (command == COMMAND.SUBMIT) {
$('#Submit').val(command.name);
var photosAttached = '@Model.Survey.SitePhotoes.Count()';
console.log('processCommand: submit - begin');
if (photosAttached >= 1) {
console.log('processCommand: submit photos attached.');
return true;
} else {
console.log('processCommand: prompt messi.');
new Messi('Are you sure you wish to submit as no inspections photos are currently attached?', {
title: command.name + ' Inspection',
buttons: [{ id: 0, label: 'Yes', val: 'Y', btnClass: 'btn-success' },
{ id: 1, label: 'No', val: 'N', btnClass: 'btn-danger' }],
modal: true,
callback: function (val) {
if (val == 'Y') {
console.log('processCommand: yes.');
return true;
}
else {
console.log('processCommand: no.');
return false;
}
}
});
}
console.log('processCommand: submit - end');
}
}
: 자바 스크립트 기능 다음
<div id="buttonCommnads">
<button type="submit" class="k-button cancel" id="save" value="Save" title="Save inspection so it may be submitted at a later time" onclick="processCommand(COMMAND.SAVE);">Save</button>
<button type="submit" class="k-button" id="Submit" value="Submit" title="Submit inspection" onclick="return processCommand(COMMAND.SUBMIT);">Submit</button>
@*<button type="submit" class="k-button" id="email" title="Generate draft email for inspection photos" onclick="processCommand(COMMAND.EMAIL);">Email</button>*@
<button type="button" class="k-button" id="cancel" title="Discard changes" onclick="location.href='@Url.Action("Index", "Inspections")'">Cancel</button>
</div>
과 : 아래
는 내 코드의 조각이다 웹 개발에 상당히 새로운 것이므로 제 무지를 용서하십시오. 어떤 도움이라도 대단히 감사합니다.빈스.
답장을 보내 주셔서 감사합니다. 변경 사항을 입력했는데 이제 다음 오류가 표시됩니다. function statement에 이름이 필요합니다. 문제가 뭔지 아십니까? –
죄송합니다. html 줄에 대괄호가 누락되었습니다. 지금 사용해보십시오 –
도움을 주셔서 감사합니다. event.preventDefault()를 추가해야했습니다. –