简体   繁体   English

如何检查textArea是否为空并启用或禁用特定按钮?

[英]How to check if a textArea is empty and enable or disable a particular button?

It is coming with the button disabled, however as soon as I write something in the textArea the button does not enable! 它带有禁用的按钮,但是,一旦我在textArea中写入内容,该按钮就不会启用!

MY CODE: 我的密码:

function teste(){
  btnEnviar = document.getElementById('btnAnalisarImagem');
  txtAreaInserirURLImagem = document.getElementById('inserirURLImagem').value;

  if(!txtAreaInserirURLImagem){
    return btnEnviar.disabled = true;
  } else {
    return btnEnviar.disabled = false;
  }
}

您需要在内容更改时再次调用函数,通常是通过处理诸如keyup事件或(以处理诸如粘贴之类的其他更改) input

You need to add this snippet like so 您需要像这样添加此代码段

btnEnviar = document.getElementById('btnAnalisarImagem');
btnEnviar.onKeyUp = teste

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM