当按html按钮不起作用时显示iframe-javascript

时间:2018-11-13 15:58:56

标签: javascript html css

我仅在使用javascript单击按钮时才尝试显示iframe,但是它不起作用,我也不知道为什么。

//I tried this way. did not work.

document.querySelector(".buttonweek").addEventListener('click', function()      {ThisWeek();});

function ThisWeek(){
  document.querySelector("#week").style.display = "block";
}

//then I tried that way. did not work.

document.getElementById("idweek").addEventListener('click', function() {ThisWeek();});

function ThisWeek(){
  document.getElementById("week").style.display = "block";
}
iframe{
    display:none;
    width: 1280px;
    height: 1000px;
}
<ul>
<li><button type="button" class="buttonweek" id="idweek">Hot This Week</button></li>
    
<iframe src="thisweek.php" id="week"></iframe>
</ul>

我也尝试过强迫性地使用onclick,它也没有用!!

如果有人读过这篇文章,谢谢!

1 个答案:

答案 0 :(得分:-1)

这应该对您有帮助

window.onload = function(){

document.getElementById("idweek").addEventListener('click', function(){

document.getElementById("week").style.display = "block";

});

}
iframe{
display: none;
}
<ul>
<li><button type="button" class="buttonweek"  id="idweek">Hot This Week</button></li>
    
<iframe src="thisweek.php" id="week"></iframe>
</ul>