jQuery - 在 toggle();中启用/禁用选择框



我有一个实例,我想根据单击更改选择框的文本和状态。

$("#foo").click(function(){
 $("#mytext").toggle();
 $(this).text($(this.text() == 'on' ? 'off' : 'on');
 // here i also want to enable and disable a select box, not sure how to do this other   then checking if the value of (this).text is on or off.
});

多谢!

var status = $(this).text();
$('#dropdownId').prop('disabled',status != 'on');