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

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

    This works fine .. here btnAddCat is button id

    $('#btnAddCat').click(function(){
            var eventCategory=$("input[name=txtCategory]").val();
            alert(eventCategory);
        });
    

提交回复
热议问题