我有jQuery包含会改变弹出页面上表单的动作但是我想让窗口开启器能够控制弹出窗口的表单动作......这可能吗?
弹出HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<body onLoad=chgAction();>
<script>
function chgAction() {
$('#search').attr('action', 'myNewActionTarget.html');
}
</script>
<base href="http://vahud.com/">
<form id="search" method="GET" action="doWork.php">
First Name <input type="text" name="fname" value="Tom"><br>
Last Name <input type="text" name="lname" value="Chambers"><br>
<input type="submit" class="form-submit" value="Search">
</form>
这是在我的窗口开启.. ..以上是myform.htm中将弹出的形式..我希望能够将动作转换器向下移动到窗口打开页面..以获得同样的结果我在表格中得到它..
开窗器JS:
window.open('myform.htm','mywindow','width=300,height=300');
答案 0 :(得分:0)
你快到了。你需要将你的javascript包装在document.ready中,以便它在表单存在后绑定。
$(document).ready(function() {
var popup = window.open('/' + window.URL_PREFIX + '/', '_blank');
popup.onload = function() {
$(popup.document.body).attr('action', 'myNewActionTarget.html');
};
chgAction();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<body>
<base href="http://vahud.com/">
<form id="search" method="GET" action="doWork.php">
First Name
<input type="text" name="fname" value="Tom">
<br>Last Name
<input type="text" name="lname" value="Chambers">
<br>
<input type="submit" class="form-submit" value="Search">
</form>