[英]Preventing new line in textarea
我正在使用聊天功能(使用Vue),并且正在使用textarea进行输入,因此溢出包装起来了,对于编写较长消息的用户更易读。 不幸的是,当用户按下Enter键并提交时,光标会在提交之前移至新行,使UX感觉良好。 关于如何使用香草Javascript禁用换行符的任何想法? 如您所见,我尝试添加了replace()函数,但无济于事。
我的文字区域:
<textarea id="btn-input" type="text" class="input-group_input" rows="4"
placeholder="Type your message here..." v-model="body"
@keydown.enter="postReply()">
</textarea>
我的提交方法:
postReply() {
this.$http.post('/api/chat/' + this.session.id + '/replies', {
body: this.body
}).then((response) => {
this.body.replace(/(\r\n|\n|\r)/gm,'');
this.body = '';
this.replies.unshift(response.data);
}).catch((error) => {
})
},
使用@keydown.enter.prevent="postReply"
。 这将阻止enter
键的默认操作,该操作将创建换行符,但仍会调用您的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.