JS Print Save user input content

Source: Internet
Author: User

When using JS to print the local page, encountered the user's new input content can not be printed out, after observation, I found that I used the JS printing method is to read the page source code, and user input content if not write it to the page source code, is not printed, the following is my solution:

Gets the label itself JQuery.fn.outerHTML = function (s) {    return (s)? This.before (s). Remove (): $ ("<Hill_man>"). Append ( This.eq (0). Clone ()). html ();}; String.prototype.contains = function (str) {    return This.indexof (str) >-1? true:false;};/ /save user Input function Saveuserinput () {    $ ("Input[type=text]"). each (function () {        $ (the). Bind ("Change", function ( {            var old = $ (this). outerHTML ();            var GHF = $ (this). Val ();            var newstr = "";            if (Old.contains ("value")) {                newstr = old.replace (/value= "*"/, "value=" "+ GHF +" ' ");            } else {                newstr = old.replace (/type= "text"/, "type= ' text ' value= '" + GHF + "'");            }            $ (this). outerHTML (NEWSTR);        });    

When used, you only need to call the Saveuserinput method when the page is loaded, so that when the contents of the text box change, the new content will be written to the source code so that the text entered by the user can be printed out.

JS Print Save user input content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.