简体   繁体   English

当选中单选按钮时,如何从跨度中获取Apple? jQuery的

[英]How do i get the Apple from the span when the radio button is checked? Jquery

I'm trying to get the text in span when the radio button is checked. 我正在尝试在选中单选按钮时获取文本。

<input type="radio" name="choice" value = 0 class="option-input radio"><span id="answer0">Apple</span></input>

My Jquery: 我的Jquery:

var answer = ($('input[name="choice"]:checked').val());
var answer = $('input[name="choice"]:checked + span').text();

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

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