按下空格时比警报消息显示 [英] when pressing space than alert message display

查看:80
本文介绍了按下空格时比警报消息显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个登录表单.在文本框中输入密码时,我不想允许空间.

I am creating a login form. I want to not allow space when entreing password in textbox.
Or
when entreing space at that time a alert message show.

推荐答案

<input type="text" id="txtSearch" onkeypress="KeyPress(event);" />

<script>
    function KeyPress(e)
    {
       
        if (typeof e == 'undefined' && window.event) { e = window.event; }
        if (e.keyCode == 32)
        {
            alert('Space not allowed');
        }
    }
    </script>



试试这个:
HTML:
Hi,
Try this:
HTML:
<asp:TextBox runat="server" ID="TextBox1" onkeypress="KeyPress(this);" />


JavaScript:


JavaScript:

<script type="text/javascript" language="javascript">
    function KeyPress(value)
    {
        if (value.keyCode == 32)
        {
            alert('Space not allowed');
            return false;
        }
    }
</script>



祝一切顺利.
--Amit



All the best.
--Amit


if (value.keyCode == 32)
        {
            alert('Dont Type Space');
            return false;
        }


这篇关于按下空格时比警报消息显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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