在页面上显示特定的div后,允许在登录表单上按下key 13 [英] allowing keypress 13 on login form after specific div is displayed on page

查看:108
本文介绍了在页面上显示特定的div后,允许在登录表单上按下key 13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,用户在登录前必须先查看一些文本.它位于一个隐藏的div中,将在表单上的号召性用语单击后立即显示.我已经禁用了回车键,但是在显示带有文本的div之后,我想允许用户使用它.到目前为止,这就是我所拥有的,但是结果是整个体验都被禁用了回车键.

I have a login form where the user must view some text before they login. It is in a hidden div that will display after fist click event of a call to action on the form. I have disabled the enter key, but I would like to allow the user to use it after the div with the text is displayed. This is what I have so far, but the result is a disabled enter key for the entire experience.

$(document).ready(function () {
    $('#textbutton').click(function () {
        $('#textbox').toggle();
        $('.usernameDiv,.passwordDiv').hide();
        $('#textbutton').hide();
        $('#submitbtn').attr('target', '_parent');
    });

    $('#form').keypress(function (e) {
        if(e.which == 13) {
            e.preventDefault();
        }

        if($('#textbox').is(':visible') 
            && ($('#form').val().length > 1)) {
            return;
        }
    });
 });

推荐答案

发送表单的方法很少. 最好完全阻止提交表单.

There is few other ways to send form. It's better to block submitting form at all.

$(function(){
  $('#form').submit(function(){
    if( ! $('#textbox').is(':visible') )
       return false;
  });
});

这篇关于在页面上显示特定的div后,允许在登录表单上按下key 13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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