how do I print a html form along with its contents

前端 未结 2 2044
眼角桃花
眼角桃花 2020-12-04 03:48

I made and form along with a button to print the form. The form gets printed BUT none of the user input shows up. Is there some way to include the user input?



        
2条回答
  •  难免孤独
    2020-12-04 04:12

    Dynamically typed values are not part of what .html() gets you. (This comes down to the difference between properties and attributes.)

    You can however set the value attribute of each input field to its current value, using something like this:

    $('form input[type=text]').each(function() {
      $(this).attr('value', $(this).val());
    });
    

    – then .html() would get you those as well.

    http://jsfiddle.net/b39xpoou/ (Simplified example, using a div element to output the HTML, using only text input fields, … but should be easy enough to adapt/modify.)

提交回复
热议问题