简体   繁体   English

从行内的div查找最接近的值

[英]Find closest value from div inside row

I'm trying to find the value from a form within clicked row form. 我试图从单击的行窗体内的窗体中查找值。 I'm using this script. 我正在使用此脚本。 I'm able to get the value from form field. 我能够从表单字段获取值。 But it's giving me the same value and it's only giving me value from first row if clicking any row. 但这给了我相同的价值,并且仅在单击任何行时才给我第一行的价值。

I want to open the form on click of td link inside row with the classname ".followupform" After opening ".followupform" link(form). 我想在打开“ .followupform”链接(窗体)后单击类名为“ .followupform”的行内的td链接打开表单。 I want to get the value from fields by clicking on ".updatefollowupstatus" of the current row. 我想通过单击当前行的“ .updatefollowupstatus”从字段中获取值。

$(".updatefollowupstatus").click(function(e){ 
  var row = $(this).closest('td>.popover-content>form')
  var status= $(row).find(".fformstatus").val();
  var comment= $(row).find(".fformcomment").val();
  var ffid= $(row).find(".fformffid").val();
  alert(ffid);
});


    <td style="text-align:center">
                  <a href="#" class="followupform"><i class="fa fa-edit"></i></a>                           <div class="hide img-rounded popover-content">
                     <strong style="text-align:center">Update Followup Status</strong><span class="pull-right ffclose" style="cursor: pointer;"><i class="fa fa-close"></i></span>
                     <hr>
                      <form class="form-inline" role="form">
                        <div class="form-group">
                          <select class="form-control fformstatus" name="fformstatus">
                            <option value="0">Followups Status</option>
                            <option value="VM">VM</option>
                            <option value="Callback">Callback</option>
                            <option value="Rude">Rude</option>
                            <option value="Done">Done</option>
                          </select>         
                        </div>  
                        <div class="form-group">  
                          <textarea placeholder="Follow up Comment overview" class="form-control fformcomment"></textarea>
                          <input type="text" class="fformffid" hidden="" name="fformffid" value="15">
                        </div>        
                        <div class="form-group">  
                          <div class="btn btn-primary updatefollowupstatus">Update »</div>                                  
                        </div>
                      </form>
</div><!-- Form Content -->
                  </td>

I used all possible way. 我用了所有可能的方式。 but I think there is some mistake or other way to do that. 但我认为这样做有些错误或其他方法。 My aim is to update feedback of the current row and send value through ajax to process. 我的目的是更新当前行的反馈,并通过ajax发送值进行处理。

Better to use the .parents() method, as form is the parent element of the button clicked. 最好使用.parents()方法,因为form是单击按钮的父元素。

Try following code. 尝试以下代码。

$(".updatefollowupstatus").click(function(e){ 
   var frm = $(this).parents('form');
   var status= $(frm).find(".fformstatus").val();
   var comment= $(frm).find(".fformcomment").val();
   var ffid= $(frm).find(".fformffid").val();
   alert(ffid);
});

You are using wrong selector in .closest('td>.popover-content>form') in [closest()][1], just use .closest('form') , 您在[closest()] [1]的.closest('td>.popover-content>form')中使用了错误的选择器,只需使用.closest('form')

 $(".updatefollowupstatus").click(function(e) { var row = $(this).closest('form'); var status = $(row).find(".fformstatus").val(); var comment = $(row).find(".fformcomment").val(); var ffid = $(row).find(".fformffid").val(); alert(status + ',' + comment + ',' + ffid); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <table> <tr> <td style="text-align:center"> <a href="#" class="followupform"><i class="fa fa-edit"></i></a> <div class="hide img-rounded popover-content"> <strong style="text-align:center">Update Followup Status</strong><span class="pull-right ffclose" style="cursor: pointer;"><i class="fa fa-close"></i></span> <hr> <form class="form-inline" role="form"> <div class="form-group"> <select class="form-control fformstatus" name="fformstatus"> <option value="0">Followups Status</option> <option value="VM">VM</option> <option value="Callback">Callback</option> <option value="Rude">Rude</option> <option value="Done">Done</option> </select> </div> <div class="form-group"> <textarea placeholder="Follow up Comment overview" class="form-control fformcomment"></textarea> <input type="text" class="fformffid" hidden="" name="fformffid" value="15"> </div> <div class="form-group"> <div class="btn btn-primary updatefollowupstatus">Update »</div> </div> </form> </div> <!-- Form Content --> </td> </tr> <tr> <td style="text-align:center"> <a href="#" class="followupform"><i class="fa fa-edit"></i></a> <div class="hide img-rounded popover-content"> <strong style="text-align:center">Update Followup Status</strong><span class="pull-right ffclose" style="cursor: pointer;"><i class="fa fa-close"></i></span> <hr> <form class="form-inline" role="form"> <div class="form-group"> <select class="form-control fformstatus" name="fformstatus"> <option value="0">Followups Status</option> <option value="VM">VM</option> <option value="Callback">Callback</option> <option value="Rude">Rude</option> <option value="Done">Done</option> </select> </div> <div class="form-group"> <textarea placeholder="Follow up Comment overview" class="form-control fformcomment"></textarea> <input type="text" class="fformffid" hidden="" name="fformffid" value="16"> </div> <div class="form-group"> <div class="btn btn-primary updatefollowupstatus">Update »</div> </div> </form> </div> <!-- Form Content --> </td> </tr> </table> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM