Home > Web Front-end > JS Tutorial > body text

vue and jquery monitor user input status code sharing in real time

小云云
Release: 2018-02-08 13:17:57
Original
1751 people have browsed it

This article mainly shares with you the use of vue and jquery to monitor the user input status in real time. The effect is that when the input value is not entered, the button is disabled. Please refer to this article for the specific operation code. I hope it can help you.

Achievement effect: input value is not entered, button is disabled

jquery operation code:

html


##

<input type="text" name="" placeholder="请输入用户名" id="userName" >
 <button class="disabled" id="login">登录</button>
Copy after login

css


 .disabled {
  pointer-events: none;//禁用点击事件
  cursor: default;//鼠标禁用
  opacity: 0.4;
  }
Copy after login

js

##

//监听input里的值
$(&#39;#userName&#39;).on(&#39;input propertychange&#39;,function(){
   if(this.value.length != 0){
      $(&#39;#login&#39;).removeClass(&#39;disabled&#39;);
   }else{
      $(&#39;#login&#39;).addClass(&#39;disabled&#39;);
   }
 });
Copy after login

Vue operation code:

html

##
<template>
  <p>
       <input type="text" placeholder="请输入用户名" v-model="userName"> 
      <button :disabled="forbidden" >登录</button>  
  </p>
</template>
Copy after login

js

export default{
  data(){
     return{
       forbidden:false,
       userName:null
     }
  },
  methods:{
     if(this.userName == null){
       this.forbidden = true;
     }else{
       this.forbidden = false
     }
  }
}
Copy after login

Related recommendations:


Jquery real-time monitoring input value example

js and jquery real-time monitoring of the oninput and onpropertychange methods of the input box value

js real-time monitoring of the text box State method_javascript skills

The above is the detailed content of vue and jquery monitor user input status code sharing in real time. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!