JQuery或Javascript获得标签文本在表格单元格与单选按钮和标签的组合

JQuery or Javascript to get label text in table cell with combination of radio button and label

本文关键字:标签 单元格 单选按钮 组合 表格 Javascript 文本 JQuery      更新时间:2023-09-26

我有一个表,第一列是单选按钮和标签的组合。请不要建议我把文本放在单选按钮,因为我有一个函数,每行标签上的值,所以我不能合并它。

HTML:

<table id="template" style="display:none;">
    <tr>
        <td class="hidden"></td>
        <td>
            <input type="radio" name="rbDefaultPrice" class="radio" />
            <label style="font-size: 1em" class="price"></label>
        </td>
        <td class="startdate"></td>
        <td class="enddate"></td>
    </tr>
</table>

脚本:

$("#template").click(function (e) {
    //JQuery or JS to get label text value
});

选择标签,然后获取html。

$("#template").click(function (e) {
     //console.log or whatever you want to do with it
     console.log(  $('.price').html()  )
});