【发布时间】:2014-09-06 13:14:03
【问题描述】:
我正在做一个项目,当用户完成同一页面中的表单时需要刷新。代码如下:
page1.jsp
<div id="codeRefer">
<input type="" type="text" name="numcode" id="numcode" value="42988715">
<script language="javascript">
var a = Math.ceil(Math.random() * 9) + '';
var b = Math.ceil(Math.random() * 9) + '';
var c = Math.ceil(Math.random() * 9) + '';
var d = Math.ceil(Math.random() * 9) + '';
var e = Math.ceil(Math.random() * 9) + '';
var f = Math.ceil(Math.random() * 9) + '';
var g = Math.ceil(Math.random() * 9) + '';
var h = Math.ceil(Math.random() * 9) + '';
var code = a + b + c + d + e + f + g + h;
document.getElementById("numcode").value = code;
function ValidCaptcha() {
var str1 = removeSpaces(document.getElementById('numcode').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2) {
return true;
alert(str1);
} else {
return false;
}
}
function removeSpaces(string) {
return string.split(' ').join('');
}
</script>
</div>
<input type="button" value="REFRESH" onClick="javascript:refer()">
<script language="javascript">
function refer() {
$('#codeRefer').load(window.location.href + '#codeRefer');
}
</script>
我得到的是,当我单击刷新时,文本框的值会被刷新,但是,我在第一个刷新按钮的底部得到另一个相同的“刷新”按钮。 我不知道为什么会出现另一个按钮。谢谢各位!
I think there is a bug in my code.
Which keeps repeating the whole content whenever I press the REFRESH button.
HELP me with this guys GURU'S.
【问题讨论】:
-
你需要使用 iframe!
-
'工作小提琴将得到答复'。您希望有人为您制作小提琴,对吗?
-
{ return true; alert(str1); }看起来很不错 -
@Yury Tarabanko,是的,你是对的。请问你能做到吗?
-
当您使用
window.location.href + '#codeRefer'时,您实际上是在 div 中加载整个页面。你只需要在 div 中加载#codeRefer的内容。试试$('#codeRefer').html()
标签: javascript jquery html ajax jsp