我能夠完成任務這樣做。在財政上,我在我的文本框和單選按鈕上有id。該單選按鈕id =「check1」textbox id =「text1」,單選按鈕id =「check2」textbox id =「text2」。然後在我的拒絕ID我有單選按鈕id =「checker1」和文本框id =「text1」等。
因此,基於哪一個選擇它將啓用它並將其變爲綠色,或禁用並將其變爲紅色。
這是代碼。
<script type="text/javascript">
$(document).ready(function() {
//Goes through each and if click adds css and removes disable
$(":radio[id^=check]").click(function() {
var textId = "#" + this.id.replace("check", "text");
$(textId).removeAttr("disabled").css('background-color', '#99FF66').css('color', '#000')
});
//Goes through each and if checked adds disabled and turns red
$(":radio[id^=checker]").click(function() {
var textId = "#" + this.id.replace("checker", "text");
$(textId).attr("disabled", "disabled").css('background-color', '#FF0033').css('color', '#FFFFFF')
});
//alert("test");
});
</script>
我不確定有人知道你真的想要做什麼或問。考慮更詳細地描述你的場景。我猜想,有一段時間你會解釋你想要做什麼,有人會建議如何解決它。 –
好的,所以目前我有多個單選按鈕,涉及多個文本框。文本框全部禁用,以開始。此代碼在單擊某個單選按鈕時啓用某個文本框。但是,一旦單擊單選按鈕,然後取消單選按鈕,什麼也沒有發生,它應該保持啓用狀態,當它應該禁用和恢復。所以,我的問題是。當單選按鈕未被選中時,如何禁用文本框?或者當選擇它,然後取消選擇它?那有意義嗎?對不起,我不清楚。 – Alex