我有一个表格,显示来自mysql表的数据,它有一个需要用户输入的字段。每行还包含一个div。该表格有两个功能。
第一个函数是显示来自外部PHP页面的信息,该页面处理每行输入字段上的值,并以结果的形式将结果发送到行div
第一个功能完美,这里是脚本:
<script type="text/javascript">
function get(row){ //row being processed, defined in onchange="get(x)"
$.post ('getpeopleinjobs.php',{ //data posted to external page
postvarposition: form["position"+row].value, //variable equal to input box, sent to external page
postvarjob: form["job"+row].value, //variable equal to input box, sent to external page
postvarperson: form["person"+row].value, //variable equal to drop down list, sent to external page
postrow: row}, //variable equal row being processed, sent to external page
function(output){
$('#training'+row).html(output).show(); //display external results in row div
});
}
</script>
我需要帮助的第二个功能。我需要再次重复相同的javascript函数。但是,我不想将行变量发送到外部页面,而是将它们发送到弹出页面。当我单击div时,应该触发此功能。
我有弹出窗口的以下javascript。
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open( url,'popUpWindow','height=400,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>
What I want to do is send the variables to the popup page, the same variables that were sent to the external page.
so what I am aiming for is something like this:
<script type="text/javascript">
// Popup window code
function newPopup(url) {
function get(row){ //row being processed, defined in onchange="get(x)"
$.post ('trainingneeded.php',{ //my popup page
postvarposition: form["position"+row].value, //these variables must be posted to the popup page
postvarjob: form["job"+row].value, //these variables must be posted to the popup page
postvarperson: form["person"+row].value, //these variables must be posted to the popup page
postrow: row}, //these variables must be posted to the popup page
);
}
popupWindow = window.open( //open popup with the above variables posted to it
url,'popUpWindow','height=400,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>
如何让上述功能完成?使用href是最好的主意,或者div可以有一个onclick事件。
感谢您提前协助。
答案 0 :(得分:1)
不,它无法发布到弹出窗口。您可以将这些变量包含在URL中,并将其作为get。
或者你可以添加target =&#34; _blank&#39;到表格,让它打开一个新的窗口。
它不会成为一个弹出窗口,但是现在浏览器大多会阻止它们,或者无论如何都会在标签中打开它们,所以它可能无关紧要。
另一个选项是打开弹出窗口,然后使用javascript简化write()
页面内容。