
JS怎么在onload方法外部取到里面的值
1个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>导航</title>
<style type="text/css">
<script>
function drawOnCanvas ()
{
var x = 1;
var img = new Image;
var callback = function ()
{
img.src = "pic.jpg";
x = 2;
return x;
}
img.onload = callback;
img.onload ();
console.log (x);
document.body.appendChild (img);
}
window.onload = drawOnCanvas;
</script>
</head>
<body>
</body>
</html>
追问
十分感谢回答,可是还是取不到里面的值,只要原因是由于得不到e.target呀
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询