提交表单时的性能问题
我有一个 html 表单可以验证用户输入。问题是即使在本地主机上也需要花费很多时间才能跳转到“操作”页面。代码如下
<form action="Activity.php" method="GET" >
<div style="display:none">
<input type="text" id="chapter" name="chapter"/>
<input type="text" id="book" name="book"/>
<input type="text" id="activity" name="activity"/>
</div>
<input type="image" src="includes/file.png" onClick="return validateForm()" title="Create New Activity" >
</form>
validateForm 的代码是:
function validateForm()
{
document.body.style.cursor='wait';
if(document.getElementById("book").value==null || document.getElementById("book").value==""
|| document.getElementById("chapter").value==null || document.getElementById("chapter").value=="")
{
document.body.style.cursor='default';
alert("You cannot create an activity at the selected location.");
return false;
}
var name=prompt("Please enter the New Activity Name","New Activity Name");
if (name==null || name=="")
{
document.body.style.cursor='default';
return false;
}
document.getElementById('activity').value=encodeURI(name);
return true;
}
如果我删除上面函数中的提示,它会立即跳转到 Activity.php 页面,但是如果我保留提示并询问活动名称,则需要很长时间才能加载所需的页面(可能是因为表单提交过程被提示中断,单击提示“确定”按钮后,提交会再次开始!!不知道:S)在什么情况下从用户那里获取输入应该是一种解决方案(快速的解决方案)正在提交表格?谢谢!!
I have got a form in html that validates the user input. The problem is it takes a lot of time even on localhost to jump to the 'action' page. Heres the code
<form action="Activity.php" method="GET" >
<div style="display:none">
<input type="text" id="chapter" name="chapter"/>
<input type="text" id="book" name="book"/>
<input type="text" id="activity" name="activity"/>
</div>
<input type="image" src="includes/file.png" onClick="return validateForm()" title="Create New Activity" >
</form>
The code for validateForm is :
function validateForm()
{
document.body.style.cursor='wait';
if(document.getElementById("book").value==null || document.getElementById("book").value==""
|| document.getElementById("chapter").value==null || document.getElementById("chapter").value=="")
{
document.body.style.cursor='default';
alert("You cannot create an activity at the selected location.");
return false;
}
var name=prompt("Please enter the New Activity Name","New Activity Name");
if (name==null || name=="")
{
document.body.style.cursor='default';
return false;
}
document.getElementById('activity').value=encodeURI(name);
return true;
}
If I remove the prompt in above function, it instantly jumps to the activity.php page, but if I keep the prompt and ask the activity name, it takes a long time to load the desired page (may be cauze the form submitting process was interrupted by the prompt and on clicking the prompts 'ok' button the submission starts again!!no idea :S)what should be a solution (a fast one) to take input from a user when a form is being submitted? thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该对象不存在:
document.getElementById('activity')
This object does not exist:
document.getElementById('activity')
试试这个。
Try this.