getting the value of dynamically created textbox using jquery

前端 未结 6 933
悲&欢浪女
悲&欢浪女 2020-12-18 09:50

I\'m having a hard time with getting the value of my dynamically appended textboxes. I\'m using the $.each function to iterate all of the textboxes according to

6条回答
  •  执笔经年
    2020-12-18 10:39

    In general its better to use a class for it, because ids are a unique identifier, you should not work with arrays in them. if you want to handle them server side after a post you better do it this way :

    
    
    
    
    
    

    and for your script

    $('#save_grade_button').click(function (){
    
             $('.studentGrade').each(function() {
               var grade =  $(this).val();
               alert(grade);
             });
    
    
         });
    

    Edit: since jQuery 1.7, you should bind your event with .on()

    $('#save_grade_button').on('click', function (){
       $('.studentGrade').each(function() {
          var grade =  $(this).val();
          alert(grade);
       });
    };
    

    OR if the save button will be dynamically too

    $(document).on('click', '#save_grade_button', 'gradeSaveClick' function (){
       $('.studentGrade').each(function() {
          var grade =  $(this).val();
          alert(grade);
       });
    };
    

提交回复
热议问题