Setting an attribute in Jquery not working

I have the following function which limits the amount of characters you can enter into a text area. What's meant to happen is, if the text length is higher than the text limit, set an attribute of `disabled="disabled"` on the submit button, but it isn't getting set, my function code is as follows: function limitChars(textid, limit, infodiv) { var text = $('#'+textid).val(); var textlength = text.length; if(textlength > limit) { $('#' + infodiv).html('You cannot write more then '+limit+' characters!'); $('input#submit').attr('disabled', 'disabled'); } else { $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.'); } } It's specifically the `$('input#submit').attr('disabled', 'disabled');` bit that isn't working. Any ideas?
I'm absolutely certain this is a duplicate, I remember answering a very similar question a few weeks ago (and another before that). I can't find it though...

以上就是Setting an attribute in Jquery not working的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准