简体   繁体   中英

Internet Explorer empty div link

I want to make an empty div react to click.

HTML

<div id="closeButton"></div>

CSS

#closeButton {
height:100px;
position:absolute;
right:0;
top:0;
width:100px;    
z-index:1000;
border:1px solid blue;
}

Javascript

$('#closeButton').click(function() {
alert("yo");
});

This works perfectly in Firefox, but not in Internet Explorer. Why?

I solved it by adding a 1x1 transparent png as background-image. This made the div render properly and possible to use for click functions.

这似乎是一个奇怪的错误,唯一的解决方案是将IE设置为符合HTML4标准的模式

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Try this:

$(function(){
  $('#closeButton').click(function(){
      alert("yo");
  });
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM