如何从页面获取包含按钮输入值的所有内容?

时间:2022-10-31 13:44:57

I would need to be able to copy the whole page I am viewing with a simple button. I have found a way to work this out but unfortunately it does not include the values added to inputs. here is the fonction selecting everything in between my 2 html tags.

我需要能够通过一个简单的按钮复制我正在查看的整个页面。我已经找到了解决这个问题的方法,但不幸的是它没有包含添加到输入中的值。这是选择我的2个html标签之间的所有内容的功能。

function getPageHTML() {
  return "<html>" + $("html").html() + "</html>";
} 

and then I just simply echo out a button calling the function

然后我只是简单地回显一个调用该函数的按钮

echo "<button class=\"Button\" onclick=\"console.log(getPageHTML());\">Print all html</button>";

this works fine but none of the values of inputs are there?

这工作正常,但输入值没有?

Thank you

2 个解决方案

#1


1  

I think you should get all value of your form inputs then write on inline, for example:

我认为你应该获得表单输入的所有值然后写入内联,例如:

function getPageHTML() {
    // Apply for all your input
    $('input').attr('value', $('input').val());

    return "<html>" + $("html").html() + "</html>";
} 

#2


1  

For some reason you need to set the value of each input field explicitly.

出于某种原因,您需要显式设置每个输入字段的值。

You can use the code from this question for that purpose:

您可以将此问题的代码用于此目的:

$("input").each(function(){
    $(this).attr("value", $(this).val());
});

Then your call to $("html").html() will work properly.

然后你对$(“html”)。html()的调用将正常工作。

#1


1  

I think you should get all value of your form inputs then write on inline, for example:

我认为你应该获得表单输入的所有值然后写入内联,例如:

function getPageHTML() {
    // Apply for all your input
    $('input').attr('value', $('input').val());

    return "<html>" + $("html").html() + "</html>";
} 

#2


1  

For some reason you need to set the value of each input field explicitly.

出于某种原因,您需要显式设置每个输入字段的值。

You can use the code from this question for that purpose:

您可以将此问题的代码用于此目的:

$("input").each(function(){
    $(this).attr("value", $(this).val());
});

Then your call to $("html").html() will work properly.

然后你对$(“html”)。html()的调用将正常工作。