JS - input输入框点击回车提交或者进行别的操作

$("input").keydown(function(event){
if (event.keyCode == 13) {
        /* 提交或者别的操作 */
}
});

转载于:https://www.cnblogs.com/500m/p/11434103.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个支持多输入的 el-input 输入框的完整代码(使用了 Vue.js 和 Element UI): ```html <template> <div> <el-input :value="inputValue" @input="handleInput" @keyup.enter="handleEnter" placeholder="请输入内容" ></el-input> <ul> <li v-for="(item, index) in inputList" :key="index">{{ item }}</li> </ul> </div> </template> <script> export default { data() { return { inputValue: "", // 输入框的值 inputList: [] // 多输入的内容列表 }; }, methods: { handleInput(value) { // 监听输入框的输入事件 const lastChar = value[value.length - 1]; // 获取最后一个字符 if (lastChar === "," || lastChar === ",") { // 如果是逗号或者中文逗号 const str = value.slice(0, -1); // 去除逗号 this.inputList.push(str); // 将输入框的值加入到列表中 this.inputValue = ""; // 清空输入框的值 } }, handleEnter() { // 监听回车事件 this.inputList.push(this.inputValue); // 将输入框的值加入到列表中 this.inputValue = ""; // 清空输入框的值 } } }; </script> ``` 这个组件中,使用了 `inputValue` 和 `inputList` 两个 data 属性,分别表示输入框的值和多输入的内容列表。在 `handleInput` 方法中,监听输入框的输入事件,如果输入的最后一个字符是逗号或者中文逗号,则将输入框的值加入到列表中,并清空输入框的值;在 `handleEnter` 方法中,监听回车事件,将输入框的值加入到列表中,并清空输入框的值。最后,在模板中通过 v-for 渲染多输入的内容列表。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值