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

前端 未结 10 921
予麋鹿
予麋鹿 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 11:57

    Only one thing more: when you´re using the "crasis variable assignment" you need to use double cotes too AND you do not need to use the "input" word!:

    valInput  = $(`[name="${inputNameHere}"]`).val();
    

提交回复
热议问题