找到你要的答案

Q:How to replace all form input fields

Q:如何替换所有表单输入字段

I am trying to replace all form input field with their respective value and underline them as well as but when I select on dropdown only the first value appears even if I select third or second. Here's what I have tried:

jQuery('.btn-print').click(function() {

  jQuery(".form1").find(':input').each(function() {
    if (jQuery(this).val() && jQuery(this).attr('type') !== 'hidden') {

      jQuery.trim(jQuery(this).replaceWith('<u>' + jQuery(this).val() + '</u>'));
    } else if (jQuery(this).val() === '') {
      jQuery(this).replaceWith('________');
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form class="form1">
  <input type="text" value="ABC" />
  <input type="text" value="DEF" />
  <select name="acces_specfi" class="selectpicker" data-size="10" data-style="btn-info">
    <option value="public">public</option>
    <option value="public">private</option>
  </select>
  <button type="submit" class="btn-print" />
</form>

我试图用各自的值替换所有形式的输入字段和下划线以及当我选择下拉只有第一个值的出现,即使我选择第三或第二。这是我尝试过的:

jQuery('.btn-print').click(function() {

  jQuery(".form1").find(':input').each(function() {
    if (jQuery(this).val() && jQuery(this).attr('type') !== 'hidden') {

      jQuery.trim(jQuery(this).replaceWith('<u>' + jQuery(this).val() + '</u>'));
    } else if (jQuery(this).val() === '') {
      jQuery(this).replaceWith('________');
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form class="form1">
  <input type="text" value="ABC" />
  <input type="text" value="DEF" />
  <select name="acces_specfi" class="selectpicker" data-size="10" data-style="btn-info">
    <option value="public">public</option>
    <option value="public">private</option>
  </select>
  <button type="submit" class="btn-print" />
</form>
jquery  html  forms