简体   繁体   中英

How can I disable input field spaces with MooTools?

I can't find this anywhere, we need to disable the space bar (spaces) in a input field of our form using MooTools 1.2

I have a solution for jQuery which doesn't work, however we have our site based completely on our framework of choice.

Thank you for your help!!

<form action="signup.php" method="POST">
<input id='username' name='signup_username' type='text' class='home_signin_field' maxlength='50' size='22' onclick="this.value='';" onfocus="this.value='';" onblur="this.value=!this.value?'Your Name':this.value;" value="Your Name">
</form>

I don't use mootools, but it looks like you're looking for something like this:

window.addEvent('domready', function() {
    $('username').addEvent('keydown', function(event){
        if (event.key == 'space') { event.stop(); return false; } 
});
});

Example here: http://jsfiddle.net/CVC7d/12/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM