开发者

Function not working on jQuery 1.6.x (but worked on 1.5.x)

开发者 https://www.devze.com 2023-04-04 02:33 出处:网络
This works in 1.5.2, but doesn\'t on 1.6.2. The button won\'t get \'enabled\'. I think it has to be with the .attr

This works in 1.5.2, but doesn't on 1.6.2. The button won't get 'enabled'. I think it has to be with the .attr

How could i fix this?

function checkMessageForm() {
    var message_chars = $("#form_dm_text").val().length;
    console.log(message_chars)开发者_JAVA技巧;
    if (message_chars > 0 && message_chars < 14001) $("#form_dm_submit").attr("disabled", "");
    else
    $("#form_dm_submit").attr("disabled", "disabled");
}

Thanks!


You should delete the disabled attribute:

$("#form_dm_submit").removeAttr("disabled");

You can see the effect of removeAttr('disabled') versus attr('disabled', '') here:

http://jsfiddle.net/ambiguous/JMvKr/


Instead of .attr("disabled", ""), try .removeAttr("disabled") ?


I like to use the .prop(propertyName, value) solution. Mostly it is just another option that wasn't mentioned here.

function checkMessageForm() {
    var message_chars = $("#form_dm_text").val().length;
    console.log(message_chars);
    var disable = message_chars > 0 && message_chars < 14001;
    $("#form_dm_submit").prop("disabled", disable);
}

attr() also accepts a true and false as the value to enable/disable.

0

精彩评论

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

关注公众号