javascript - jQuery disable/enable submit button

Pubblicato il: 14 giugno 2023
sul canale di: Code Samples
211
8

#short
#javascript
#html
#jquery
I have this HTML:
input type="text" name="textField" /
input type="submit" value="send" /

How can I do something like this:

When the text field is empty the submit should be disabled (disabled="disabled").
When something is typed in the text field to remove the disabled attribute.
If the text field becomes empty again(the text is deleted) the submit button should be disabled again.

I tried something like this:
$(document).ready(function(){
$('input[type="submit"]').attr('disabled','disabled');
$('input[type="text"]').change(function(){
if($(this).val != ''){
$('input[type="submit"]').removeAttr('disabled');
}
});
});

…but it doesn't work. Any ideas?


In questa pagina del sito puoi guardare il video online javascript - jQuery disable/enable submit button della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code Samples 14 giugno 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 211 volte e gli è piaciuto 8 spettatori. Buona visione!