我需要你的帮助。我快到了.. :)
我想在提交前预览我的表单。但是form.submit() ; 不起作用。
这是我的代码:
HTML:
<form action="" method="post" name="frmaction" onSubmit="return preview(this);">
<label>First Name:</label>
<input name="fname" type="text" size="40" value="" />
<label>Last Name:</label>
<input name="lname" type="text" size="40" value="" />
</form>
Javascript:
<script>
function preview(form){
var dia_log;
$( "label" ).each(function(i,val) {
dia_log +=$(this).text() + " " + $(this).next().val()+"<br/>";
});
dia_log =dia_log.replace('undefined', '');
$.confirm({
'title' : 'Are all these information is correct?',
'message' : dia_log,
'buttons' : {
'Yes' : {
'class' : 'blue',
'action': function(){
form.submit();
}
},
'No' : {
'class' : 'gray',
'action': function(){}
}
}
});
return false;
}
</script>
查询:
(function($){
$.confirm = function(params){
if($('#confirmOverlay').length){
// A confirm is already shown on the page:
return false;
}
var buttonHTML = '';
$.each(params.buttons,function(name,obj){
// Generating the markup for the buttons:
//buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';
buttonHTML += '<input type="submit" class="button '+obj['class']+'" value="'+name+'"/>';
if(!obj.action){
obj.action = function(){};
}
});
var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<h1>',params.title,'</h1>',
'<p>',params.message,'</p>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){
// Calling the action attribute when a
// click occurs, and hiding the confirm.
obj.action();
$.confirm.hide();
return true;
});
});
}
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
}
})(jQuery);
希望我能得到你的回应。
非常感谢。