在用javascript截取提交后,无法“提交()`html表单 [英] Unable to `submit()` an html form after intercepting the submit with javascript

查看:147
本文介绍了在用javascript截取提交后,无法“提交()`html表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试拦截提交表单以更改关键字标签的值。

I'm trying to intercept the submission of a form in order to change the value of my keywords label.

我有以下代码:

<HTML>
<FORM name="searchForm" method="get" action="tmp.html" >
<input type="text" name="keywords" />
<input type="button" name="submit" value="submit" onclick="formIntercept();"/>
</FORM>
<SCRIPT language="JavaScript">
document.searchForm.keywords.focus();
function formIntercept( ) {
    var f = document.forms['searchForm'];
    f.keywords.value = 'boo';
    f.submit();
};
</SCRIPT>
</HTML>

当我在chrome中运行此选项并单击提交按钮时,关键字标签将更改为 boo ,但javascript控制台说:

When I run this in chrome and click the submit button the keywords label changes to boo, but the javascript console says:

 Uncaught TypeError: Property 'submit' of object <#an HtmlFormElement> is not a function.

如何使用操纵的关键字提交表单?

How can I submit the form with the manipulated keywords?

推荐答案

<html>
<head></head>
<body>
<form name="searchForm" method="get" action="tmp.html" onsubmit="formIntercept(this);">
<input type="text" name="keywords" />
<input type="submit" name="submit" value="submit"/>
</form>
<script type="text/javascript">
document.searchForm.keywords.focus();
function formIntercept( form ) {
    form.keywords.value = 'boo';
    //form.submit();
}
</script>
</body>
</html>

这篇关于在用javascript截取提交后,无法“提交()`html表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆