如果我理解正确,您想从父级打开的子窗口(弹出窗口)访问父窗口表单输入值。 如果是这样,我建议你看一下window.opener
财产 http://www.w3schools.com/jsref/prop_win_opener.asp
如果你有这样的父窗口的情况:
HTML:
<form id="testForm">
<input type="text" id="testVariable" value="" />
<input type="submit" />
</form>
JS:
$(document).ready(function() {
$('#testForm').on('submit', function(e){
e.preventDefault();
window.open('http://www.yourdomain.com/chilwindow.php', 'ChildWindow', 'menubar=0,resizable=1,location=0,scrollbars=0,status=0,toolbar=0,width=580,height=520');
});
});
然后在你的子窗口/弹出窗口(http://www.yourdomain.com/chilwindow.php),你应该可以访问你的父风流量是这样的:
$(document).ready(function() {
var testVariableNew = window.opener.$("#testVariable").val();
console.log('Got value from parent window: ' + testVariableNew);
});
或者:
$(document).ready(function() {
var testVariableNew = $('#testVariable', window.opener.document).val();
console.log('Got value from parent window: ' + testVariableNew);
});
如果你想要做一个POST请求执行以下操作:
$("#testForm").submit(function(e) {
e.preventDefault();
var myVariable = $(this).find("#testVariable").val();
var myUrl = $(this).attr("action");
var posting = $.post(myUrl , { temp: myVariable });
posting.done(function(result) {
console.log(result);
});
});
呃,这是什么形式呢?如果你想在某个地方重定向,你可以设置表单的'action'属性? – adeneo
http://www.w3schools.com/tags/att_form_action.asp - 查看“尝试自己”的代码以了解操作属性的工作原理。希望它有帮助。 – Falt4rm
我说使用jquery时! – Richard