我有一個表格,看起來像這樣需要使用JavaScript或jQuery的一個表單提交幫助
@using (Html.BeginForm("ActionMethod","MyController FormMethod.Post)) {
<button type="submit" value="Generate" name="action" class="button" id="btnGenerate">Generate Form</button>
<button type="submit" value="Confirm" name="action" class="button" id="btnConfirm">Confirm</button>
}
和我的JavaScript看起來像這樣
<script type="text/javascript">
$(function() {
var genOverlay = jQuery('<div id="overlay"><div class="innerblock box-shadow"><p>Please remember to print the registration form and sign both copies.</p><div><a id="btnClose" href="#" class="button">Close</a></div></div>');
var confirmOverlay = jQuery('<div id="overlay"><div class="innerblock box-shadow"><p>Changes can not be made to this record once it has been confirmed. Are you sure you would like to confirm this form?</p><div> <a id="btnConfirmConfirmation" href="#" class="button">Confirm</a> <a id="btnCancel" href="#" class="button button-red">Cancel</a></div></div>');
$('#btnGenerate').click(function() {
genOverlay.appendTo(document.body);
return false;
});
$('#btnConfirm').click(function() {
confirmOverlay.appendTo(document.body);
return false;
});
$('#btnConfirmConfirmation').live('click', function() {
// Need help on submitting the form with the input button value of btnConfirm.
// $('#btnConfirm').submit(); does not work
// return true;
});
$('#btnClose').live('click', function() {
genOverlay.remove();
});
$('#btnCancel').live('click', function() {
confirmOverlay.remove();
});
});
</script>
我將如何去實現btnConfirmConfirmation點擊覆蓋只需提交表單通常的「確認」的行動值?
感謝所有幫助
嗨,羅布,你碰巧知道我應該如何通過表單提交按鈕「btnConfirm」的價值? – zSynopsis
是的。改變元素的'type'屬性:'$(「#btnConfirm」)。attr(「type」,「hidden」);'。當表單被提交時,最多傳遞一個按鈕元素:點擊具有名稱屬性的「submit」按鈕。 –