简体   繁体   English

html url输入禁用句子后的键盘自动空格(移动)

[英]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. 我有html输入字段,在移动设备中,键盘会在句子后自动添加空格。

This is problematic for a input of type "url". 这对于类型为“ 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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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