使用vue与jquery实时监听用户输入状态的操作代码
实现效果:input未输入值,按钮禁用
jquery操作代码:
html
<input type="text" name="" placeholder="请输入用户名" id="userName" > <button class="disabled" id="login">登录</button>
css
.disabled { pointer-events: none;//禁用点击事件 cursor: default;//鼠标禁用 opacity: 0.4; }
js
//监听input里的值 $('#userName').on('input propertychange',function(){ if(this.value.length != 0){ $('#login').removeClass('disabled'); }else{ $('#login').addClass('disabled'); } });
Vue操作代码:
html
<template> <div> <input type="text" placeholder="请输入用户名" v-model="userName"> <button :disabled="forbidden" >登录</button> </div> </template>
js
export default{ data(){ return{ forbidden:false, userName:null } }, methods:{ if(this.userName == null){ this.forbidden = true; }else{ this.forbidden = false } } }
总结
相关推荐
85477104 2020-11-17
84901334 2020-07-28
EdwardSiCong 2020-11-23
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17