duandanxiu6965 2019-01-13 23:31
浏览 88

电子邮件验证实时消息,电子邮件随机显示并保留

I am trying to display the email typed in the email input field in a validation message. The input field also already checks my database for registered emails and then displays a message depending on the result. I then added this code from here.

The result is that the validator will return with its message, but with a blank span for the email. If I type a key, the email will show up for a split second and then disappear(due to the validator rechecking the database), yet the "Confirmation will be sent to" message will then come back but email span remains blank.

<script>
//echo typed in email
    $('#youremail').keydown(function() {
    $('#youremail-confirm').text($(this).val());
    });
//check if the current user is already taken
$('#youremail').keyup(function(){
    var user = $('#youremail').val();
    var userlength = document.getElementById("youremail").value.length;
    if(userlength >= 8 && userlength <= 60) {
        $('.checkemail').html("");
        $.ajax({
            type: "GET",
            url: "<?php bloginfo('template_url'); ?>/ajax/check-username.php",
            data: "user=" + user,
            success: function(data){
                $('.checkemail').html(data);
            }
        });
    };
});
</script>
    <div class="form-label">
        <label for="youremail">Email Address <i>*</i></label>
        <small class="checkemail"></small>
    </div>
    <div class="form-input">
        <input type="email" name="youremail" id="youremail" class="input longinput" value="<?php echo $youremail; ?>" />
    </div> <!-- email -->



<?php 
if (strlen($_GET['user']) > 3 && strlen($_GET['user']) <= 30) {
if (username_exists($_GET['user'])) { //sanitizing is done by WordPress
    echo '<span class="checkusererr">This email is already used. Please <label for="lger" style="font-weight:bold;cursor:pointer;">click here log in</label> or enter another one.</span>';
} else {
    echo '<span class="checkuserok">Confirmation with be sent to <span id="youremail-confirm" style="font-weight:bold;"></span></span>';
} 
} ?>
  • 写回答

1条回答 默认 最新

  • doujianchao7446 2019-01-14 00:31
    关注

    I think you need to bind your event to a container and then the event will bubble up to #youremail. In this case you would use the .form-input div. This is just an example of the concept:

    $('.form-input').on('keydown', '#youremail', function ()
    {
        $('#youremail-confirm').text($(this).val());
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)