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

前端 未结 10 911
予麋鹿
予麋鹿 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:56

    //name directly given
    
    var meetingDateFrom = $("input[name=MeetingDateFrom]").val();
    
    //Handle name array
    
     var selectedValues = $('select[name="Roles[]"] option:selected').map(function() {
        arr.push(this.value);
      });
    

提交回复
热议问题