[英]how to obtain html page including all tags and element values using javascript
i use document.documentElement.outerHTML and got everything except it does not contain the current state of all input elements (textbox, checkbox, select, radio buttons etc) 我使用document.documentElement.outerHTML并得到了一切,除了它不包含所有输入元素(文本框,复选框,选择,单选按钮等)的当前状态。
i can use jquery to obtain element values and update the html string. 我可以使用jquery获取元素值并更新html字符串。 but i hope there is a standard way to do this. 但我希望有一种标准的方法可以做到这一点。 any idea? 任何想法?
Here is the code: 这是代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function () {
$("#me").click(function () {
alert( document.documentElement.outerHTML )
});
});
</script>
<style type="text/css">
</style>
</head>
<body>
<form>
<input id="me" type="submit" value="test" />
<input id="Text1" type="text" value="" />
</form>
</body>
</html>
Have you tried this? 你有尝试过吗?
alert($('html').html());
It will alert the whole HTML element except the DOCTYPE . 它将警告除DOCTYPE之外的整个HTML元素 。
Judging by what you said in your comments, you really just want the key value pairs of the form submission. 根据您在评论中所说的话,您实际上只需要表单提交的键值对。
I would first look into using jQuery's .serialize()
我首先要研究使用jQuery的.serialize()
If jQuery's .serialize()
isn't what you are looking for, you should be able to reference each value individually, personally I would first identify your form: 如果jQuery的.serialize()
不是您想要的,则您应该能够单独引用每个值,我个人将首先确定您的表单:
<form id="formOfStuff">
Then in pure javascript you can do something like: 然后,在纯JavaScript中,您可以执行以下操作:
var me = formOfStuff.elements["me"].value;
var text1 = formOfStuff.elements["text1"].value;
alert("me=" + me + " text1 = " + text1);
or In jQuery: 或在jQuery中:
var me = $("#me").val();
var text1 = $("#text1").val();
alert("me=" + me + " text1 = " + text1);
The values you entered are part of your POST data and would also be accessible server side on whatever page you are posting to in your form's action. 您输入的值是POST数据的一部分,也可以在表单操作中要发布到的任何页面的服务器端访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.