How to get a value of an element by name instead of ID

前端 未结 10 901
予麋鹿
予麋鹿 2020-12-07 11:53

How could I get the value of an element via the attribute name instead of the ID. eg if I use by id it would be $(\'#id\').val();

相关标签:
10条回答
  • 2020-12-07 12:11

    you can also use the class name.

    $(".yourclass").val();
    
    0 讨论(0)
  • 2020-12-07 12:12

    What element is used for the part with a green background? Just type the name of the element without "<" and ">" characters. For example type P, not <P> if the answer is the <P> element.

    0 讨论(0)
  • 2020-12-07 12:18
    $('[name=whatever]').val()
    

    The jQuery documentation is your friend.

    0 讨论(0)
  • 2020-12-07 12:18
    let startDate = $('[name=daterangepicker_start]').val();
    alert(startDate);
    
    0 讨论(0)
提交回复
热议问题