jQuery - Disable Form Fields

后端 未结 5 1560
礼貌的吻别
礼貌的吻别 2020-12-13 01:54

I have 2 fields: 1 input, 1 select box.

Is it possible to make the browser disable one of the fields when the user uses the other?

For example, if the user i

5条回答
  •  执念已碎
    2020-12-13 02:19

    The jQuery docs say to use prop() for things like disabled, checked, etc. Also the more concise way is to use their selectors engine. So to disable all form elements in a div or form parent.

    $myForm.find(':input:not(:disabled)').prop('disabled',true);
    

    And to enable again you could do

    $myForm.find(':input:disabled').prop('disabled',false);
    

提交回复
热议问题