简体   繁体   English

从相应的单选按钮获取输入文本

[英]Get input text from corresponding radio button

I have two radio buttons with an input text for each radio button, where a person selects a radio button and enters text. 我有两个单选按钮,每个单选按钮都有一个输入文本,一个人选择一个单选按钮并输入文本。

The question is: How do I get the typed text for the selected radio button? 问题是:如何获取所选单选按钮的键入文本?

<div class="form-group">
<label for="textNome" class="control-label">Type text</label>
</div>
<div class="radio">
<label><input type="radio" name="mode" value="one" checked /> Selection 
1</label>
<input id="end" class="form-control" type="text">
</div>
<div class="radio">
<label><input type="radio" name="mode" value="two"checked /> Selection 
2</label>
<input id="end" class="form-control" type="text">
</div>

You could try this using jQuery: 你可以尝试使用jQuery:

console.log($("input[type='radio']:checked").next());

Bear in mind that since these are radio buttons, you shouldn't label both as checked . 请记住,由于这些是单选按钮,因此不应将两者标记为已checked

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM