【问题标题】:performance issue on submitting a form提交表单时的性能问题
【发布时间】:2011-09-23 15:02:49
【问题描述】:

我有一个验证用户输入的 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)在提交表单时,应该有什么解决方案(快速解决方案)从用户那里获取输入?谢谢!!

【问题讨论】:

  • 您为什么要使用prompt 来收集信息以放入表格中?你没有违背表单的目的吗?
  • 您的方法有很多不正确的地方。为什么不使用验证表单提交的 标记?
  • @pacman :我确实尝试过这个,看看它是否有任何区别,但它很有效。我正在使用输入类型的图像因为我需要一个图像作为用户可以单击的按钮。
  • @gddc。好点,但是当用户单击图像按钮时我需要输入。在那种情况下,这是我知道的唯一解决方案。
  • @Salmanmahmood :这并不重要,但为什么您将输入内容放在隐藏的 div 中?如果你想向服务器发送隐藏的输入,你只需要指定 input type=hidden。

标签: javascript html forms submit


【解决方案1】:

此对象不存在:document.getElementById('activity')

【讨论】:

  • 对不起它确实存在!!输入错误。编辑它。谢谢指出!
【解决方案2】:

试试这个。

function validateForm()
    {
        document.body.style.cursor='wait';
        if(document.getElementById("book").value || 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)
        {
            document.body.style.cursor='default';
            return false;
        }

        //document.getElementById('activity').value=encodeURI(name);
        return true;

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-28
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    • 2016-12-26
    • 2013-07-22
    相关资源
    最近更新 更多