如何给iframe中的元素设置属性,如下图和代码

问题

如何给iframe中的元素设置属性,如下图和代码

clipboard.png

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  </head>
  <body>
    <iframe id="iframe1" src="https://www.hao123.com/" frameborder="0"></iframe>
    <script>
      $(function() {
        $("#iframe1")
          .contents()
          .find("body")
          .attr("title", "aaaa");
      });
    </script>
  </body>
</html>
阅读 4.8k
1 个回答

<iframe src = "xxx" style = "width:100px height:100px"></iframe>
这是加宽度和高度的方法,其他属性也是这样,比如加个id
<iframe src = "xxx" style = "width:100px height:100px" id = "iframe1"></iframe>
再加个frameboredr,顺序随便改
<iframe src = "xxx" style = "width:100px height:100px" id = "iframe1" frameborder="0"></iframe>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题