简体   繁体   English

获取最近输入 Jquery 的值

[英]Get Value of closest input Jquery

when i click on id save_newsection i need value of class school_name means school name当我点击 id save_newsection 时,我需要 class school_name 的值表示学校名称

<div class="school_form_submit">
  <div class="form-group">
    <label class="control-label col-md-3">School Name<span class="required"> * </span>
    </label>
    <div class="col-md-9">
      <input type="text" class="form-control school_name" placeholder="Please Enter School Name" value="dfghdf" name="school_name_submit">
    </div>
  </div>
</div>
<div class="modal-footer">
  <button type="button" class="btn dark btn-outline" data-dismiss="modal">Close</button>
  <button type="button" id="save_newsection" class="btn green">Save changes</button>
</div>
</div>

If there is only one input with the class .school_name , use this如果类.school_name只有一个输入,请使用此

$("#save_newsection").click(function() {
    var value = $("input.school_name").val();
    // use value
});

If there could be more of them throughout the document use this:如果整个文档中可能有更多的人,请使用以下内容:

$("#save_newsection").click(function() {
    var value = $(".school_form_submit .school_name").val();
    // use value
});

 $("#save_newsection").click(function() { var value = $(".school_form_submit .school_name").val(); alert(value); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="school_form_submit"> <div class="form-group"> <label class="control-label col-md-3">School Name <span class="required"> * </span> </label> <div class="col-md-9"> <input type="text" class="form-control school_name" placeholder="Please Enter School Name" value="dfghdf" name="school_name_submit"> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn dark btn-outline" data-dismiss="modal">Close</button> <button type="button" id="save_newsection" class="btn green">Save changes</button> </div>

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

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