var btn = document.getElementById('butn');
function change () {
if (this.value === '显示') {
this.value = '隐藏'
} else {
this.value = '显示'
}
alert(this);
}
if(btn.addEventListener){
btn.addEventListener('click', change);
}else if(btn.attachEvent){
btn.attachEvent("click",change);
alert("出来没"); //ie8兼容 alert这个出来了但是 这块没有反应。这是为什么呢?
}
<input type="button" id="butn" value="显示/隐藏" />
<div>标题</div>
<div>内容</div>
ie是onclick 另外 不要用this