简体   繁体   English

如何使用Javascript或JQuery更改HTML IFrame元素属性

[英]How to change HTML IFrame element attribute with Javascript or JQuery

Having a challenge currently with this kind of html iframe element. 目前,使用此类html iframe元素存在挑战。 I have this CSS snippet in my HTML file like this: 我的HTML文件中有以下CSS代码段,如下所示:

...
<style>
iframe[src^="https://apis.google.com"] {
display: none;
}
</style>
...

Does any one know how I can change the display to "visible" for this iframe[src^="https://apis.google.com"] { display: none; } 是否有人知道如何将此iframe[src^="https://apis.google.com"] { display: none; }的显示更改为“可见” iframe[src^="https://apis.google.com"] { display: none; } iframe[src^="https://apis.google.com"] { display: none; } element using javascript or jquery onclick function? iframe[src^="https://apis.google.com"] { display: none; }元素是使用javascript还是jquery onclick函数?

First, give the iframe an id attribute, like id="iframeid". 首先,为iframe提供一个id属性,例如id =“ iframeid”。 Then, run this javascript: 然后,运行以下javascript:

document.getElementById("iframeid").style.display = "visible";

Element without display style is displayed by block . 没有显示样式的元素按block显示。 When using jquery's .show() , it changes element's display to block . 当使用jquery的.show() ,它将元素的显示更改为block Easy and simple in jquery: 简单易用的jQuery:

$('#link').click(function() {
  $('iframe[src="https://apis.google.com"]').show();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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