我有一个表格,表格显示来自 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 事件。
提前感谢您的帮助。