gpt4 book ai didi

javascript - html 框架的复选框标签

转载 作者:行者123 更新时间:2023-12-03 03:21:13 24 4
gpt4 key购买 nike

例如,如果我们单击标签文本,我想切换(选中/取消选中)box.html 页面的复选框。

我已经包含了带有 iframe 的 box.html 页面。

Index.html

<html>
<body>
<iframe src="box.html" height="25px" width="100px">

</iframe>
<label for="box">
checkbox
</label>
</body>
</html>

Box.html:

<html>
<body>
<input type="checkbox" id="box">
</body>
</html>

最佳答案

首先,两个页面(Main 和 iframe)应该来自同一个域,否则会抛出跨域错误。

第一页

<html><head>
<script>
function delegate() {
var iframe = document.getElementById("myIframe");
iframe.contentWindow.change();
}
</script></head><body>
<iframe id="myIframe" src="box.html" height="25px" width="100px"></iframe>
<label for="box" onclick="delegate()">
Click Here.
</label></body></html>

第二页

<html><head>
<script>
function change() {
document.getElementById('box').checked = !document.getElementById('box').checked;
}
</script></head><body>
<input type="checkbox" id="box"></body></html>

关于javascript - html 框架的复选框标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46568406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com