我写了一个表格,需要用户编译才能进行一些计算。AJAX 脚本使结果出现在“提交”按钮之后的 div 中。但是我注意到不耐烦的用户倾向于多次单击“提交”,因为他们没有看到结果显示在按钮本身之后。我想知道如何滚动到 div ([id=results]) 的底部,其中包含用户单击“提交”时的结果。当然,提交按钮不能包含 href 属性,所以我不知道如何创建一个 html 锚点......我想我还需要一点 jquery。
编辑:源代码:calculator1.php
<form name="formpeso" id="formpeso" action="" method="post">
<div>
<label for="altezza">Inserisci la tua altezza <strong>(in cm)</strong></label>
<input type="text" name="altezza" id="altezza" onkeyup="commadot(this)" value="" />
[FOO... FOO...]
<input type="submit" id="submit" value="send data" />
</div>
</form>
<div id="results">RESULTS WILL APPEAR HERE AFTER CLICKING ON SUBMIT</div>
这是验证文本字段并将结果(处理为calculator2.php)显示为的函数
$(document).ready(function(){
$("#formpeso").validate({
debug: false,
rules: {
altezza: {min:20, required: true},
peso: {min:1, required: true},
vita: {min:1, required: true},
fianchi: {min:1, required: true},
collo: {min:1, required: true},
polso: {min:1, required: true},
},
messages: {
altezza: "Non hai compilato il campo!<br />",
peso: "Non hai compilato il campo!<br />",
vita: "Non hai compilato il campo!<br />",
fianchi: "Non hai compilato il campo!<br />",
collo: "Non hai compilato il campo!<br />",
polso: "Non hai compilato il campo!<br />",
},
submitHandler: function(form) {
// do other stuff for a valid form
$.post('calculator2.php', $("#formpeso").serialize(), function(data) {
$('#results').html(data);
});
}
});
});
演示:链接