[英]Toggle Show and Enable Textfiled When Certain Radio Button is Selected
我希望能夠在每次選擇“其他”單選按鈕時顯示並啟用一個輸入字段(最初是隱藏和禁用的),並且在選擇其他單選按鈕時也將隱藏並禁用一個輸入字段。 我已經獲得了該腳本來適當地顯示和隱藏文本字段,但是我想知道如何才能啟用和禁用它
$('input[name="x_description"]').bind('change',function(){
var showOrHide = ($(this).val() == "Other") ? true : false;
$('#other_program_text').toggle(showOrHide);
});
我知道這是顯示字段並啟用文本字段的方法,但無法弄清楚如何將它們組合在一起,
$(this).show().prop('disabled', false);
預先感謝,丹
$('input[name="x_description"]').bind('change',function(){
if ( showOrHide == true ) {
$('#other_program_text').show().prop('disabled',false);
} else if ( showOrHide == false ) {
$('#other_program_text').hide().prop('disabled',true);
}
});
您想使用$(this).attr()函數在HTML元素上設置屬性。 使用一個參數將讀取傳遞的參數,使用兩個參數將其設置。
像$(this).attr(“ enabled”,true)
您可以使用“點擊”方法
$('input[name="x_description"]').click(function() {
if($('#radio_button').is(':checked')) {
alert("it's checked"); //do your stuff
}
});
如果您的內容是動態生成的,則使用“實時”方法
$('input[name="x_description"]').live('click',function() {
if($('#radio_button').is(':checked')) {
alert("it's checked"); //do your stuff
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.