将数组的元素循环到变量中以进行比较

时间:2018-02-25 16:22:52

标签: event-listener

启动html ----------------------

div id="pageWrapper"> //page wrapper
<div id="page-image"><img src="./images/lightHouseB.png"></div>
<div id="man-image"><img src="./images/sailor.png"></div>
<section>
<header>There Are Things in the Dark, can you Find them? </header>
<!-- basic html title page --> 


<div id="textBox">
<a id="mousee" href="#">Hidden Ships</div></a>
</div>
</section>   

html结束点-----------------------------------

 window.onload = eventMonitor();

function eventMonitor(){
    document.getElementById('manimage').addEventListener('onmouseover', popMap(), false);
    document.getElementById('mousee').addEventListener('click', shipsSlider(), false);

    function popMap(url='shipsSlide.html',windowName, w, h) {
        var left = (screen.width/2)-(w/2);
         var top = (screen.height/2)-(h/2);
          return window.open(url=" ", "Ship Pictures", toolbar='no', directories="no", status='no');
    }

不断获取null值 - 无法读取eventlistener的null属性。

1 个答案:

答案 0 :(得分:1)

您需要将函数引用到window.onload,并在窗口加载后调用它。

在这里看到差异。

window.onload = onload;


function onload(){

  console.log('DOM loaded');

}

在这里我引用任何onload将返回的内容,在本例中是一个函数。

window.onload = onload(); // This will return the anonymous function of onload
// __________________|^^|

function onload(){

  return function(){ 
      console.log('DOM loaded');
  }

}

所以你要做的就是删除(),以便你的代码成为:

window.onload = eventMonitor; // eventMonitor will be run once windows loads.