1

感谢过去的帮助。我又问你了。

我想要 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/在这里。谢谢!

4

3 回答 3

5

根据您的网站 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');
  });
});

有一个错字。如果这不起作用,我能想到的唯一其他方法是......不,我认为这会起作用。

于 2012-11-05T12:27:42.583 回答
0

为什么不呢,另一个不需要 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/

于 2012-11-05T12:38:30.530 回答
0

这个标记:

<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/

于 2012-11-05T12:36:27.583 回答