将表单值发送到已经运行的函数?

时间:2015-10-03 23:33:45

标签: javascript forms

我试图弄清楚网站的登录信息。我已经中途停止了一个codrops模板的加载动画,并且我已成功将登录工作作为提示,但我无法弄清楚如何从表单中发送值字段以相同的方式工作。该功能已经在运行......

以下是与提示一起使用的链接 http://nmbdes.com/test/r2/

以下是我尝试使用表单字段的链接。 http://nmbdes.com/test/r1/

密码是" bianca"

以下是相关代码 -

HTML

  <div id="iWrap">
        <form>
            <label>Please Enter the Password</label><br />
            <input name="pw" id="pw" type="password" required><br />
            <input name="submit" id="submit" type="button" value="submit" onClick="epw();"/>
        </form>
    </div>

JS

function startLoading() {
        // simulate loading something..
        var simulationFn = function(instance) {
            var progress = 0,
                interval = setInterval( function() {
                    progress = Math.min( progress + Math.random() * 0.1, 1 );

                    instance.setProgress( progress );

                    // reached the end
                    if ( progress === 1) {

                        var apw = "bianca";
                        var epw = document.getElementById("pw").value;
                        if (ipw != epw) {
                            alert("Sorry, wrong password!");
                            window.location.reload();
                        } else if (ipw == epw) {
                            classie.remove( container, 'loading' );
                    classie.add( container, 'loaded' );
                    clearInterval( interval );

                    var onEndHeaderAnimation = function(ev) {
                        if( support.animations ) {
                            if( ev.target !== header ) return;
                            this.removeEventListener( animEndEventName, onEndHeaderAnimation ); 
                        }

                    classie.add( document.body, 'layout-switch' );
                    window.removeEventListener( 'scroll', noscroll );

                    }

                if( support.animations ) {
                    header.addEventListener( animEndEventName, onEndHeaderAnimation );
                } else {
                    onEndHeaderAnimation();
                }
            }   
                        }

                    }, 80);
    };

这是可能的还是我需要坚持提示?

提前感谢您的帮助! XX

1 个答案:

答案 0 :(得分:0)

我想我已经过度思考了你的问题,但它似乎是一些基本的HTML和javascript。 如果我理解,你想从表格中提交密码,继续你的逻辑。

你知道,

  

在vanilla javascript中编写事件处理程序可能很烦人   跨浏览器工作,所以我建议使用像jquery这样的库   使它健壮(也更容易写)。

所以解决方案就像:

function startLoading() {
    // simulate loading something..
    var simulationFn = function(instance) {
        var progress = 0,
            interval = setInterval( function() {
                progress = Math.min( progress + Math.random() * 0.1, 1 );

                instance.setProgress( progress );

                // reached the end
                if ( progress === 1) {
                    $(form).submit(function(){
                        var apw = "bianca";
                        var epw = document.getElementById("pw").value;
                        if (ipw != epw) {
                            alert("Sorry, wrong password!");
                            window.location.reload();
                        } else if (ipw == epw) {
                            classie.remove( container, 'loading' );
                            classie.add( container, 'loaded' );
                            clearInterval( interval );

                            var onEndHeaderAnimation = function(ev) {
                                if( support.animations ) {
                                    if( ev.target !== header ) return;
                                    this.removeEventListener( animEndEventName, onEndHeaderAnimation );
                                }

                                classie.add( document.body, 'layout-switch' );
                                window.removeEventListener( 'scroll', noscroll );

                            }

                            if( support.animations ) {
                                header.addEventListener( animEndEventName, onEndHeaderAnimation );
                            } else {
                                onEndHeaderAnimation();
                            }
                        }
                    }
                });

                }

            }, 80);
    };

重要

您还需要包含jquery。