getting the value of dynamically created textbox using jquery

前端 未结 6 947
悲&欢浪女
悲&欢浪女 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:26

    If you want to stick with prefixed ids for the inputs you can use the jquery wildcard selector. ALso instead of using a jquery selector to retrieve the value of the grade you can simply use the item passed into the function. As mentioned adding a class to the input may be a more efficient way to proceed.

    $('#save_grade_button').click(function (){
    
       $.each($("input[id^='student_grde_G']"), function(i, item) { //uses wildcard selector
    
          var grade =  $(item).val();  //Use item instead of selector
              alert(grade);
          });
     });
    

    Example: http://jsbin.com/axenuj/1/edit

提交回复
热议问题