Home >Web Front-end >JS Tutorial >vue and jquery monitor user input status code sharing in real time

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

小云云
小云云Original
2018-02-08 13:17:571780browse

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>

css


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

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;);
   }
 });

Vue operation code:

html

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

js

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

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!

Statement:
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