简体   繁体   中英

html url input disable keyboard autospace after sentence (mobile)

I have html input fields and in mobile devices, the keyboard automatically adds spaces after sentence.

This is problematic for a input of type "url". How do I disable it?

I tried the following and still adds a space after the period in the domain name.

Assuming you have your input stored in a variable and that you are interested in its value only when you do a submit, you can easily trim its value with

yourInput.trim();

this will remove all leading and trailing spaces, thus cleaning your input.

If you want to delete the spaces directly when typing, you can attach that code to the change event:

yourInput.addEventListener('change', e => e.currentTarget.value.trim());

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