好吧,我猜你真的不再需要这个了。那好吧。无论如何,我都会将其发布给后代。
HTML
<form id="form">
<fieldset>
<legend>Please provide the following...</legend>
<p>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" minlength="2" type="text" required />
</p>
<p>
<label for="cemail">E-Mail (required)</label>
<input id="cemail" type="email" name="email" required />
</p>
<p>
<label for="curl">URL (optional)</label>
<input id="curl" type="url" name="url" />
</p>
<p>
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" required></textarea>
</p>
<p><input class="submit" type="submit" value="Submit"/></p>
</fieldset>
</form>
<div id="Achtung">
<h1>Achtung!</h1>
<p>You are about to provide the indicated information. Please be sure!</p>
</div>
Javascript
(function env($, log) {
$(function load() {
var $form = $("#form"),
form = $form[0],
$Achtung = $('#Achtung'),
valid = {submitHandler: Achtung};
$form.validate(valid);
function Achtung() {
var buttons = [
{text: "Ok", click: ok},
{text: "Cancel", click: close}
],
dialog = {modal: true, buttons: buttons};
$Achtung.dialog(dialog);
function ok(event, ui) {
close(event, ui, "Submit Ok'd and will continue.");
form.submit();
}
function close(event, ui, msg) {
log(msg || 'Submit canceled by user.');
$Achtung.dialog("close");
}
}
// Just so the form does not submit; comment these
// lines to verify it works.
form.submit = function blocker(event, ui) {
return !log('The form.submit() was triggered and canceled.');
};
fill();
});
// Nothing to see here...
function fill(){
var $els = $(':input[type!=submit], textarea'),
d = ['oh', 'a@b.cd', location.href, 'oh'],
$el;
$.each(d, function fill(i, v){
$el = $($els[i]);
$el.is('input') ? $el.val(v) : $el.text(v);
});
}
})(jQuery, function z(){return !console.log.apply(console, arguments)});
http://jsfiddle.net/userdude/jULBx/