Get Text of checkbox with Jquery

后端 未结 5 642
故里飘歌
故里飘歌 2020-12-06 10:24
Pre-Payment

How would I get the text \"Pre-Payment\" from this using Jquery?

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 10:55

    I'd recommend putting the text inside a tag so that you could click on it (and so that screen readers and such could make sense of your form):

    
    
    

    Then, the whole thing becomes easy:

    var text    = $('label[for=pre-payment]').text();
    var or_this = $('#pre-payment').next('label').text();
    

    I'd prefer the first option, label[for=...], as it is less fragile than the second

提交回复
热议问题