本文介绍了提交HTML表单,执行javascript函数(提醒然后重定向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过'onClick'方法调用JavaScript函数时,它具有很好的功能。
基本上它是从HTML表单中提取数据,然后根据这些数据重定向到另一页。



然而,当我按下'输入'按钮来提交表单/调用JavaScript函数,而不是使用onClick按钮来调用JavaScript函数,它不会按照我的意愿进行响应。



我想当用户按下键盘上的回车按钮时,会发生同样的情况,就好像他们要点击页面上的继续按钮(通过onClick调用该功能)。



以下是我的代码:

JS函数:

 函数completeAndRedirect(){
alert('您'几乎在那里!要完成您的输入,您只需点击下一页上的\\'继续'。 !');
location.href ='http://google.com/?SID ='+'<? echo $ CATEGORY; ?> +, +< ;? echo $ PLATFORM; ?> +, +< ;? echo $ DEVICE; ?> +&安培;电子邮件= + document.forms [0] .elements [0]。价值;
}

以下是表单:

 < form action =method =postonsubmit =completeAndRedirect()> 
< input type =textid =Edit1style =width:280; height:50; font-family:'Lucida Sans Unicode','Lucida Grande',sans-serif; font-size :的22px>
< / form>

非常感谢任何能够帮助您的人!

解决方案
 < form action =javascript:completeAndRedirect();> 
< input type =textid =Edit1
style =width:280; height:50; font-family:'Lucida Sans Unicode','Lucida Grande',sans-serif ; font-size:22px>
< / form>

更改操作指向您的函数将以不同的方式解决问题。


I have a JavaScript function that works great when I call it through an 'onClick' method.Basically what it does is pull data from a html form, and then based on that data, redirects to another page.

However, when I press the 'enter' button to submit the form/call the JavaScript function, instead of using a onClick button to call the JavaScript function, it doesn't respond as I would like it to.

I would like for when a user presses the enter button on their keyboard, the same thing happens as if they were to click the 'proceed button' on by page (which calls the function via onClick)

Here is my code:

The JS Function:

function completeAndRedirect(){
    alert('You\'re nearly there! To complete your entry, you simply need to tap \'continue\' on the next page. Good luck!');
    location.href='http://google.com/?SID='+'<? echo $CATEGORY; ?>'+','+'<? echo $PLATFORM; ?>'+','+'<? echo $DEVICE; ?>'+'&email='+document.forms[0].elements[0].value;
}

Here is the form:

<form action="" method="post" onsubmit="completeAndRedirect()">
    <input type="text" id="Edit1" style="width:280; height:50; font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:22px">
</form>

Huge thanks to anyone who can help out!

解决方案
<form action="javascript:completeAndRedirect();">
    <input type="text" id="Edit1"
    style="width:280; height:50; font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:22px">
</form>

Changing action to point at your function would solve the problem, in a different way.

这篇关于提交HTML表单,执行javascript函数(提醒然后重定向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:56