使用单选按钮(jQuery)禁用/启用文本字段 [英] Disable/enable text field with radio button (jQuery)
问题描述
感谢过去的帮助.我再次问你.
thanks for the past help. I am asking you again.
我想有2个单选按钮,它们将更改文本输入的状态(启用/禁用).
I want to have 2 radio buttons, which will change the state (Enabled/Disabled) of a text input.
我设法使它从禁用状态变为启用状态,但是问题是,当您在单选按钮之间切换时,文本字段保持启用状态.而且我不想要那个.
I managed to make it come from disabled to enabled, but the problem is, that when you are switching between radio buttons, the text fields remains Enabled. And I do not want that.
html摆弄
$(document).ready( function(){
$('#casodhoda,#casodhoda1').prop('disabled',true);
$('input[type=radio][name=radioknof1]').click( function(){
$('#casodhoda,#casodhoda1').prop('disabled',true).val('');
$(this).next('span').children('wpcf7-form-control-wrap casodhoda').prop('disabled',false).triggerHandler('focus');
});
});
编辑,修改了一点代码,以任何方式都无法再使用有效的解决方案了..我希望在加载时禁用输入字段,并且当用户单击单选按钮时,应该同时启用这两个功能并专注于第一个输入字段. http://jsfiddle.net/wLFKD/3/在这里.谢谢!
EDIT, modified a little the code, and on any way cannot get to working solution anymore.. I want the input fields to be disabled at load, and when user clicks on radio it should enable both and focus on first input field. The http://jsfiddle.net/wLFKD/3/ is here. Thanks!
推荐答案
已完全按照您的网站html进行了更改.这应该起作用:
Completely changed as per your sites html. This should work:
$(document).ready( function(){
$('#casodhoda,#casprihoda').prop('disabled',true);
$('input[type=radio][name=radioknof]').click( function(){
$('#casodhoda,#casprihoda').prop('disabled',true).val('');
$(this).next('span').children('.wpcf7-form-control').prop('disabled',false).triggerHandler('focus');
});
});
有一个错字. 如果这不起作用,我唯一想到的另一种方法是...不,我认为这会起作用.
There was a typo. If this doesn't work, the only other way I can think of is to... No, I think this will work.
这篇关于使用单选按钮(jQuery)禁用/启用文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!