这看起来像跨作品浏览器。 JavaScript函数做到这一点...
- 设定值/选择/ HTML每个表单输入的属性与用户
- 输入值/选择/ textarea的创建了一个名为“formContent”
- 新的输入元素设置“formContent”的值(由用户输入含值)的形式的元素的编码值
- 添加“formContent”元素的形式
- 提交包括由用户输入到
值的形式
这是我的示例源...
<html>
<head>
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<script type="text/javascript">
function submitFormWithValues() {
$('form input').each(function() {
this.setAttribute('value', this.value);
if (this.checked)
this.setAttribute('checked', 'checked');
else
this.removeAttribute('checked');
});
$('form select').each(function() {
var index = this.selectedIndex;
var i = 0;
$(this).children('option').each(function() {
if (i++ != index)
this.removeAttribute('selected');
else
this.setAttribute('selected', 'selected');
});
});
$('form textarea').each(function() {
$(this).html($(this).val());
});
alert(encodeURI($("form").html()));
var myInput = document.createElement("input");
myInput.type = "text";
myInput.setAttribute("name", "myInput");
myInput.setAttribute("value",encodeURI($("form").html()));
var myForm = document.getElementById("form1");
myForm.appendChild(myInput);
myForm.submit;
}
</script>
</head>
<body id="body">
<form id="form1" action="test.aspx" method="post">
<input type="text" id="input1" /><br />
<input type="text" id="input2" /><br />
<input type="submit" onclick="this.style.visibility='hidden', submitFormWithValues()" id="submit" value=" Submit " />
</form></body></html>
当页面提交的表单将类似于此...
<form id="form1" action="test.aspx" method="post">
<input type="text" id="input1" /><br />
<input type="text" id="input2" /><br />
<input type="text" name="formContent" value=" %3CINPUT%20id=input1%20value=%22first%20value%22%20jQuery1385425785747=%222%22%3E%3CBR%3E%3CINPUT%20id=input2%20value=%22second%20value%22%20jQuery1385425785747=%223%22%3E%3CBR%3E%3CINPUT%20style=%22VISIBILITY:%20hidden%22%20id=submit%20onclick=%22this.style.visibility='hidden',%20submitFormContent()%22%20value=%22%20Submit%20%22%20type=submit%20jQuery1385425785747=%224%22%3E%20" />
</form>
接收页(C#下面的例子)重建HTML通过解码formContent的值来形成元素。
using System;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Server.UrlDecode(Request.Form.Get("formcontent")));
}
}
接收页面将输出原始表单元素,包括用户输入的值。通过这种方式,输入的表单和任何值可以从一个页面传递到另一个页面,而与浏览器功能无关。
[Cross domain iframe issue]的可能重复(http://stackoverflow.com/questions/9393532/cross-domain-iframe-issue) – DevlshOne
Chrome是最新版本。 与此类似,但与跨域iframe问题有所不同。 代码包含在按下按钮时调用的函数中,即在页面完全加载后调用。 – cymorg
[Inner HTML with input values]的可能重复(http://stackoverflow.com/questions/12126497/inner-html-with-input-values) –