如果我理解正確,您想從父級打開的子窗口(彈出窗口)訪問父窗口表單輸入值。 如果是這樣,我建議你看一下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