开发者

How do i grey out the input field and the submit button

开发者 https://www.devze.com 2023-01-16 14:38 出处:网络
I want to grey out these two things the song input field and the submit button until the user enters and artist. Is there an easy way to do this via JQuery.

I want to grey out these two things the song input field and the submit button until the user enters and artist. Is there an easy way to do this via JQuery.

the id of the artist input field 开发者_JAVA百科is #request_artist


You can do something like this:

var artist = ('#request_artist');
var song = ('#request_song');
var assubmit = ('#request_submit');

song.attr('disabled', true);
assubmit.attr('disabled', true);

artist.change(function() {
  if(artist.val() > 0) {
    song.attr('disabled', false);
    assubmit.attr('disabled', false);
  } else {
    song.attr('disabled', true);
    assubmit.attr('disabled', true);
  }
});


for the input field, the submit button should be equal $('#request_artist').attr('disabled', true);


The one liner code would be :

     <input type="text" name="name" value="" id="txt1" />
     <input type="button" name="name" id="btn1" disabled="disabled" value="Submit" />

<script type="text/javascript">

            $("#txt1").keyup(function () {
                $("#btn1").attr("disabled", $.trim($("#txt1").val()) != "" ? "" : "disabled");
            });


</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消