我有这个代码:
<c:forEach items="${ sample }" var="test">
<tr>
<td><strong>${ test.test }.</strong></td> // I want to get the text
<td>
<fieldset class="span11">
<div class="control-group">
<label class="control-label"><strong>${ test.blah }</strong></label>
<div class="controls" id="question${ test.blah }">
<c:forEach var="beng" items="${ anotherSample }">
<form:radiobutton path="boom" class="question-choices" data-label="${ choices }" value="${ beng-boom }"/><br>
</c:forEach>
</div>
</div>
</fieldset>
</td>
</tr>
</c:forEach>
我想从第一个 <td>
中获取文本来自 radio button
:
到目前为止我尝试的是:
$('.question-choices').on('change', function() {
console.log( $(this).parent('tr').closest('td').text() );
});
但这会返回空字符串
最佳答案
试试这个;
$('.question-choices').on('change', function() {
console.log( $(this).closest('tr').find('td:first').find("strong").html() );
});
关于javascript - 在 jQuery 中选择动态生成的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20195772/