[英]sending arguments from one function to another through event handler
I have two functions here, the first one is triggered by a button and it is meant to trigger a second function which will change the inner html of that first buttons accompanying html area. 我在这里有两个功能,第一个是由按钮触发的,它的意思是触发第二个功能,该功能将更改伴随html区域的第一个按钮的内部html。
My problem is how to pass the arguments from the first function INTO the second one to the button and textfield have the same idnumber. 我的问题是如何将第一个函数中的参数传递给第二个函数中的按钮和文本字段具有相同的idnumber。
function doLoad(idnumber, id) {
var file = _(id).files[0];
_("Btn1_QP_"+idnumber).style.display = "none";
_("Display_QP_"+idnumber).innerHTML = "Image uploading......";
var formdata = new FormData();
formdata.append("stPic", file);
var ajax = new XMLHttpRequest();
ajax.addEventListener("load", completeHandler, false);
ajax.open("POST", "pho_stem3.php");
ajax.send(formdata);
}
function completeHandler(event) {
_("Display_QP").innerHTML = 'wahooo';
}
}
In function doLoad idnumber is given by the button and used to identify the proper button with ("Btn1_QP_"+idnumber)
在函数doLoad中,idnumber由按钮提供,并用于通过
("Btn1_QP_"+idnumber)
标识正确的按钮
how can i achieve this same selective ability in the second function completeHandler
in the event listener. 我如何在事件侦听器的第二个函数
completeHandler
中实现相同的选择能力。
I have tried 我努力了
ajax.addEventListener("load", completeHandler(idnumber), false);
ajax.addEventListener("load", ("completeHandler"+idnumber), false);
both dont work. 两者都不起作用。 how can i preserve and transmit the original argument from doLoad...
我如何保存和传递doLoad中的原始参数...
You can pass the same id number in response of ajax like this: 您可以像这样通过ajax传递相同的ID号:
function doLoad(idnumber, id) {
var file = _(id).files[0];
_("Btn1_QP_" + idnumber).style.display = "none";
_("Display_QP_" + idnumber).innerHTML = "Image uploading......";
var formdata = new FormData();
formdata.append("stPic", file);
var ajax = new XMLHttpRequest();
ajax.open("POST", "pho_stem3.php");
ajax.send(formdata);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4) {
completeHandler(idnumber);
}
}
}
function completeHandler(idnumber) {
_("Display_QP_" + idnumber).innerHTM = 'wahooo';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.