感谢您的过去帮助。我再次问你。
我想拥有2个无线电按钮,这将更改文本输入的状态(启用/禁用)。
我设法使它从禁用到启用,但问题是,当您在无线电按钮之间切换时,文本字段仍保持启用。我不想要那个。
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/在这里。谢谢!
根据您的网站html完全更改。这应该有效:
$(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');
});
});
有一个错字。如果这不起作用,我唯一能想到的是...不,我认为这会起作用。
此标记:
<input type="radio" name="radioknof" value="text1"/>
<input type="text" id="id1" disabled="disabled"/><br/><br/>
<input type="radio" name="radioknof" value="text2"/>
<input type="text" id="id2" disabled="disabled"/>
和此脚本:
$('input[name="radioknof"]').on('click', function(){
$(this).next().prop('disabled',false).siblings('input[type=text]').prop('disabled',true);
});
导致您想要的东西:http://jsfiddle.net/uefak/
为什么不,不需要JavaScript ?
的另一个解决方案// HTML
<form>
<div>
<input id="trigger-1" type="radio" name="radioknof" value="text1"/>
<label for="trigger-1"><input type="text" id="input-1" /></label>
</div>
<div>
<input id="trigger-2" type="radio" name="radioknof" value="text2"/>
<label for="trigger-2"><input type="text" id="input-2" /></label>
</div>
</form>
// CSS, but just for styling, it doesn't have functional meaning :)
form {padding: 2%}
div {margin: 1em 0}
input[type='radio'] {cursor: pointer;}
http://jsfiddle.net/nuwcf/