这是我的代码:
<!DOCTYPE html>
<HTML>
<head>
<title>Test 2</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="crossorigin="anonymous"></script>
</head>
<frameset cols="25%,*,25%">
<frame src="wishlist.html">
<frame name="frame1" src="shortcodes.html">
<frame src="portfolio.html">
</frameset>
</html>
在名为 frame1
的框架中,我有一个名为 testId
的元素。
我想要的只是将 id 为 testId
的元素隐藏在名为 frame1
的框架内。
到目前为止我已经尝试过:
$("#testId", $("#frame1").contents()).hide();
您知道为什么它不起作用吗?为什么我运行这行代码时无法隐藏元素?
这可能吗?
最佳答案
您的框架有一个名称:
<frame name="frame1" src="shortcodes.html">
但是你正在用 jquery 寻找一个 id。 以这种方式更改您的 HTML
<frame id="frame1" src="shortcodes.html">
或者以这种方式更改你的jquery:
$("#testId", $("[name=frame1]").contents()).hide();
如果这不起作用,请按以下方式访问内容:
$($('[name="frame1"]', top.document)[0].contentDocument).find('*').hide();
然后避免使用frameset
,因为它已被弃用:
https://developer.mozilla.org/it/docs/Web/HTML/Element/frameset
关于javascript - jQuery - 尝试隐藏框架内的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136420/