将单选按钮的值设置为Jquery中其他输入字段的值
我有几组单选按钮,最后一组是“其他”字段,用户可以在其中指定他们的“其他”答案 我想将“其他”单选按钮的值设置为刚刚填写的“其他”文本输入字段的值 这是我的html:将单选按钮的值设置为Jquery中其他输入字段的值,jquery,button,input,set,radio,Jquery,Button,Input,Set,Radio,我有几组单选按钮,最后一组是“其他”字段,用户可以在其中指定他们的“其他”答案 我想将“其他”单选按钮的值设置为刚刚填写的“其他”文本输入字段的值 这是我的html: <fieldset> <h3>We are online via ...</h3> <label for="online_via[1]"> <input type="radio" name="online_via" id="online_via[
<fieldset>
<h3>We are online via ...</h3>
<label for="online_via[1]">
<input type="radio" name="online_via" id="online_via[1]" value="laptop" /> Laptop
</label>
<label for="online_via[2]">
<input type="radio" name="online_via" id="online_via[2]" value="desktop" /> Desktop
</label>
<label for="online_via[3]">
<input type="radio" name="online_via" id="online_via[3]" value="mobile" /> GSM, Smartphone, PDA
</label>
<label for="online_via[4]">
<input type="radio" name="online_via" id="online_via[4]" alue="tablet" /> Tablet
</label>
<label for="online_via[other]">
<input type="radio" name="online_via" id="online_via[other]" value="other" /> Other, specify: <input type="text" id="online_via[specified]" class="other" />
</label>
</fieldset>
我一直在“未定义”。我做错了什么?Jquery绝地武士联合起来
请记住我有几套单选按钮。
P.P.S.:#online_via[指定]字段没有name属性的原因是,我希望在发布数据时忽略它,因为我希望将其值存储在#online_via[其他]字段中
期待您的回复
$(function(){
$('.other').keyup(function(){
$(this).parent().find('input[type=radio]').val($(this).val());
});
});
这对你有用吗
这对你有帮助吗?先做这个:
<label for="online_via[other]">
<input type="radio" class="otherClass" name="online_via" id="online_via[other]" value="other" /> Other, specify: <input type="text" id="online_via[specified]" class="other" />
</label>
首先要这样做:
<label for="online_via[other]">
<input type="radio" class="otherClass" name="online_via" id="online_via[other]" value="other" /> Other, specify: <input type="text" id="online_via[specified]" class="other" />
</label>
哇!你是一个真正的jquery绝地武士!我接受你的回答,但让我等10分钟。我想澄清一下为什么你的代码不起作用,这是因为jQuery在选择中如何使用
[]
。与上面的代码一样,jQuery用于在属性上搜索某些内容,因此在代码中,jQuery正在搜索属性为other的#id。所以你应该在id和类中使用字母数字。哇!你是一个真正的jquery绝地武士!我接受你的回答,但让我等10分钟。我想澄清一下为什么你的代码不起作用,这是因为jQuery在选择中如何使用[]
。与上面的代码一样,jQuery用于在属性上搜索某些内容,因此在代码中,jQuery正在搜索属性为other的#id。所以你应该在id和类中使用字母数字。
$('.other').keyup(function(){
$('.otherClass').val($(this).val());
console.log($('.otherClass').val());
});