【问题标题】:Div has onclick function but the iframe inside the div is not clickablediv有onclick功能但是div里面的iframe是不可点击的
【发布时间】:2019-10-25 02:43:38
【问题描述】:

我有一个div,它有一个功能,iframe 在这个div 中,但我的iframe 不可点击。有什么方法可以使iframe 可点击并触发与div 相同的事件或功能,其中iframe 位于其中?我将非常感谢任何建议。谢谢

<div id="t1" onclick="myFunction(this, 'test', '')" class="button-hyperlink">
    <h5>Testing</h5>
    <h6>
        <iframe id="content_iframe3" src="test.html" scrolling="no" frameborder="0"
                height="30px" width="200px" name="target-iframe"></iframe>
    </h6>
</div>

功能

function myFunction(divid, link) {
    this.clear();
    divid.style.background = "blue";
    //some conditions
}

function clear() {
    for (var i = 0; i < divItems.length; i++) {
        var item = divItems[i];
        item.style.backgroundColor = 'red';
    }
}

【问题讨论】:

    标签: javascript jquery iframe


    【解决方案1】:

    这段代码怎么样。 (与你的myFunction略有不同。)

    <div id="t1" onclick="myFunction('t1')" class="button-hyperlink">
        <h5>Testing</h5>
        <h6>
            <iframe id="content_iframe3" src="test.html" scrolling="no" frameborder="0" 
                    height="30px" width="200px" name="target-iframe"></iframe>
        </h6>
    </div>
    
    function myFunction(divid) {
        var div=document.getElementById(divid);
        div.style.background = "blue";
    }
    window.onload=function () {
      var f=document.querySelector("#content_iframe3");     
      f.contentWindow.addEventListener("click", function () {
          myFunction("t1");
      } ); 
    };
    

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2012-01-07
      • 1970-01-01
      相关资源
      最近更新 更多